美文网首页Java学习之路
Gradle的下载安装,切换国内镜像源与IDEA中配置,以及一些

Gradle的下载安装,切换国内镜像源与IDEA中配置,以及一些

作者: 椰子奶糖 | 来源:发表于2019-07-22 23:30 被阅读32次

    Gradle概念

    • Gradle是一个完全开源的构建自动化系统,它使用您在Apache Maven和Apache Ant上看到的概念。它使用基于编程语言Groovy 的特定于域的语言,将其与Apache Maven区分开来,后者使用XML进行项目配置。它还通过使用有向无环图确定任务的顺序。一些开发人员创建了Gradle并于2007年首次发布,并且在2013年,它被Google采用为Android项目的构建系统。它旨在支持预计会非常庞大的多项目构建。它还允许逐步添加到您的构建中,因为它知道项目的哪些部分已更新。不再重新执行依赖于更新部件的任务。目前,最新的稳定版本是5.x版本。它支持使用Java,Scala和Groovy进行开发和后续部署,以及将来引入的其他项目工作流程和语言。

    Gradle下载与安装

    image.png
    • 接下来是环境变量中的配置

      • GRADLE_HOME D:\IDEInstall\gradle-4.8
      • Path %GRADLE_HOME%\bin


        image.png
        image.png
    • 还有一个是本次仓库的配置,一起写了:

      • GRADLE_USER_HOME D:\IDEInstall\RepGradle


        image.png
    • 接下来是测试:gradle -v 或者-version也可以


      image.png
    • 这就安装成功了

    Gradle 的build命令

    • 下面是在命令行使用gradle build命令生成一个spring boot的Demo
    D:\workspace\IntellijIDEA\springweb>gradle build
    Starting a Gradle Daemon (subsequent builds will be faster)
    Download https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.5.21.RELEASE/spring-boot-gradle-plugin-1.5.21.RELEASE.pom
    Download https://repo1.maven.org/maven2/io/spring/gradle/dependency-management-plugin/1.0.6.RELEASE/dependency-management-plugin-1.0.6.RELEASE.pom
    Download https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-gradle-plugin/1.5.21.RELEASE/spring-boot-gradle-plugin-1.5.21.RELEASE.jar
    Download https://repo1.maven.org/maven2/io/spring/gradle/dependency-management-plugin/1.0.6.RELEASE/dependency-management-plugin-1.0.6.RELEASE.jar
    :compileJava
    Download https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-parent/1.5.21.RELEASE/spring-boot-starter-parent-1.5.21.RELEASE.pom
    :processResources
    :classes
    :findMainClass
    :jar
    :bootRepackage
    :assemble
    :compileTestJava
    :processTestResources NO-SOURCE
    :testClasses
    :test
    2019-07-22 15:04:12.787  INFO 16004 --- [       Thread-5] o.s.w.c.s.GenericWebApplicationContext   : Closing org.springframework.web.context.support.GenericWebApplicationContext@40cf6dd8: startup date [Mon Jul 22 15:04:09 CST 2019]; root of context hierarchy
    :check
    :build
    
    BUILD SUCCESSFUL
    
    Total time: 2 mins 33.213 secs
    D:\workspace\IntellijIDEA\springweb>
    

    IDEA 中配置

    image.png

    切换阿里镜像源

    在init.d(里面只有个readme.txt)文件夹中建立一个init.gradle文件


    image.png

    添加:

    allprojects{
        repositories {
            def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
            all { ArtifactRepository repo ->
                if(repo instanceof MavenArtifactRepository){
                    def url = repo.url.toString()
                    if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                        project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                        remove repo
                    }
                }
            }
            maven {
                url REPOSITORY_URL
            }
        }
    }
    

    这就好了,在build的时候会发现下载路径改成了ali的maven仓库

    尚未解决的问题:

    我的情况是这样的,配置好了运行springboot主类的时候给我报一个找不到log4j2的错误,由于我是初步接触Gradle,所以,若有大佬路过,提提建议。。。。。

    • 这是错误日志
    D:\IDEInstall\jdk1.8\bin\java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:\软件安装处\IntelliJ_IDEA\IntelliJ IDEA 2017.1.4\lib\idea_rt.jar=28513:D:\软件安装处\IntelliJ_IDEA\IntelliJ IDEA 2017.1.4\bin" -Dfile.encoding=UTF-8 -classpath D:\IDEInstall\jdk1.8\jre\lib\charsets.jar;D:\IDEInstall\jdk1.8\jre\lib\deploy.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\cldrdata.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\dnsns.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\jaccess.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\jfxrt.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\localedata.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\nashorn.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\sunec.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\IDEInstall\jdk1.8\jre\lib\ext\zipfs.jar;D:\IDEInstall\jdk1.8\jre\lib\javaws.jar;D:\IDEInstall\jdk1.8\jre\lib\jce.jar;D:\IDEInstall\jdk1.8\jre\lib\jfr.jar;D:\IDEInstall\jdk1.8\jre\lib\jfxswt.jar;D:\IDEInstall\jdk1.8\jre\lib\jsse.jar;D:\IDEInstall\jdk1.8\jre\lib\management-agent.jar;D:\IDEInstall\jdk1.8\jre\lib\plugin.jar;D:\IDEInstall\jdk1.8\jre\lib\resources.jar;D:\IDEInstall\jdk1.8\jre\lib\rt.jar;D:\workspace\IntellijIDEA\springboot-blog-01\build\classes\java\main;D:\workspace\IntellijIDEA\springboot-blog-01\build\resources\main;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-devtools\2.1.6.RELEASE\1576e4c16cf810f8c40abf404ce3641a7d56eee3\spring-boot-devtools-2.1.6.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.1.6.RELEASE\22f085f39ded75b0b454ee7731eccae68b20f17e\spring-boot-starter-2.1.6.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.1.8.RELEASE\6d7134733f05133d82440172c5f6f9fe001db7ed\spring-web-5.1.8.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.1.6.RELEASE\875d84cfa6d5655bd11238c229e7acedf344024b\spring-boot-autoconfigure-2.1.6.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.1.6.RELEASE\b8a75ec9a9c570290523c4308c2255fbea6746c0\spring-boot-2.1.6.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.11.2\f5e9a2ffca496057d6891a3de65128efc636e26e\log4j-api-2.11.2.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.3.2\934c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.1.8.RELEASE\83ab599b042a4805bbee71b6241e9d073022d704\spring-context-5.1.8.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.1.8.RELEASE\c013c5603a05bee2a80cc2ec8f3fc11b15d4de3a\spring-aop-5.1.8.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.1.8.RELEASE\e35fa81d0142ef7c1247a7dee8b1ef2dd78c6322\spring-beans-5.1.8.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.1.8.RELEASE\4f8340d8d4f52dbd527bd696358923ff4df5be1a\spring-expression-5.1.8.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.1.8.RELEASE\37fd45c92cfd05b9ad173ee1184ec4221e0f931f\spring-core-5.1.8.RELEASE.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.23\ec62d74fe50689c28c0ff5b35d3aebcaa8b5be68\snakeyaml-1.23.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.26\77100a62c2e6f04b53977b9f541044d7d722693d\slf4j-api-1.7.26.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.9.9\bfff5af9fb8347d26bbb7959cb9b4fe9a2b0ca5e\jackson-core-2.9.9.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.9.9\d6eb9817d9c7289a91f043ac5ee02a6b3cc86238\jackson-databind-2.9.9.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.9.0\7c10d545325e3a6e72e06381afe469fd40eb701\jackson-annotations-2.9.0.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\9.0.21\225a44fe65e9832f896e09f343ce107d38f3ee1b\tomcat-embed-core-9.0.21.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\9.0.21\6a7ed3ad394b36d3f0f77745f424e19e976d2d61\tomcat-embed-el-9.0.21.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\javax.validation\validation-api\2.0.1.Final\cb855558e6271b1b32e716d24cb85c7f583ce09e\validation-api-2.0.1.Final.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.3.2.Final\3789d00e859632e6c6206adc0c71625559e6e3b0\jboss-logging-3.3.2.Final.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.4.0\291658ac2ce2476256c7115943652c0accb5c857\classmate-1.4.0.jar;D:\IDEInstall\RepGradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.1.8.RELEASE\60a3bb9c802ea03c955ee26526f8aebc9dd712b6\spring-jcl-5.1.8.RELEASE.jar com.ch.blog.SpringbootBlog01Application
    ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
    Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
    Caused by: java.lang.NoClassDefFoundError: ch/qos/logback/classic/Level
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.<clinit>(LogbackLoggingSystem.java:72)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:164)
        at org.springframework.boot.logging.LoggingSystem.lambda$get$1(LoggingSystem.java:157)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
        at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet.lambda$entryConsumer$0(Collections.java:1575)
        at java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)
        at java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntrySetSpliterator.tryAdvance(Collections.java:1594)
        at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
        at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
        at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
        at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:157)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:211)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:193)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
        at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
        at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
        at com.ch.blog.SpringbootBlog01Application.main(SpringbootBlog01Application.java:10)
        ... 5 more
    Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 37 more
    
    Process finished with exit code 0
    

    相关文章

      网友评论

        本文标题:Gradle的下载安装,切换国内镜像源与IDEA中配置,以及一些

        本文链接:https://www.haomeiwen.com/subject/hmtnlctx.html