分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
把项目从Maven迁移到Gradle
作者:chszs,版权所有,未经同意,不得转载。博主主页:http://blog.csdn.net/chszs
在过去几年中,Maven已成为Java及Java EE项目事实上的构建工具,没有之一。而最近两年,Gradle获得越来越多的人使用,分走了不少Maven的用户。本文就是讲述怎样把Java EE项目从Maven迁移到Grale。
Grale是一个自动化的构建工具,类似于Ant或Maven,与这两个构建工具不同的是,Gradle引入了基于Groovy语言的DSL语法来代替XML配置,因此它的配置文件是一个Groovy文件。
安装Gradle有几种方法,最佳的方法是使用sdkman工具来安装。而要安装sdkman工具,只需简单的运行:
# curl -s get.sdkman.io | bashThanks for using... SSSSSSSSSSSSSSS DDDDDDDDDDDDD KKKKKKKKK KKKKKKK SS:::::::::::::::SD::::::::::::DDD K:::::::K K:::::K S:::::SSSSSS::::::SD:::::::::::::::DD K:::::::K K:::::K S:::::S SSSSSSSDDD:::::DDDDD:::::D K:::::::K K::::::K S:::::S D:::::D D:::::DKK::::::K K:::::KKK S:::::S D:::::D D:::::D K:::::K K:::::K S::::SSSS D:::::D D:::::D K::::::K:::::K SS::::::SSSSS D:::::D D:::::D K:::::::::::K SSS::::::::SS D:::::D D:::::D K:::::::::::K SSSSSS::::S D:::::D D:::::D K::::::K:::::K S:::::S D:::::D D:::::D K:::::K K:::::K S:::::S D:::::D D:::::DKK::::::K K:::::KKK SSSSSSS S:::::SDDD:::::DDDDD:::::D K:::::::K K::::::K S::::::SSSSSS:::::SD:::::::::::::::DD K:::::::K K:::::K S:::::::::::::::SS D::::::::::::DDD K:::::::K K:::::K SSSSSSSSSSSSSSS DDDDDDDDDDDDD KKKKKKKKK KKKKKKK mmmmmmm mmmmmmm aaaaaaaaaaaaa nnnn nnnnnnnn mm:::::::m m:::::::mm a::::::::::::a n:::nn::::::::nn m::::::::::mm::::::::::m aaaaaaaaa:::::an::::::::::::::nn m::::::::::::::::::::::m a::::ann:::::::::::::::n m:::::mmm::::::mmm:::::m aaaaaaa:::::a n:::::nnnn:::::n m::::m m::::m m::::m aa::::::::::::a n::::n n::::n m::::m m::::m m::::m a::::aaaa::::::a n::::n n::::n m::::m m::::m m::::ma::::a a:::::a n::::n n::::n m::::m m::::m m::::ma::::a a:::::a n::::n n::::n m::::m m::::m m::::ma:::::aaaa::::::a n::::n n::::n m::::m m::::m m::::m a::::::::::aa:::a n::::n n::::n mmmmmm mmmmmm mmmmmm aaaaaaaaaa aaaa nnnnnn nnnnnn Now attempting installation...Looking for a previous installation of SDKMAN...Looking for unzip...Not found.================================================================================================ Please install unzip on your system using your favourite package manager. Restart after installing unzip.================================================================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
说明需要unzip工具,执行命令安装它:
# apt-get install unzip
- 1
再次安装sdkman
# curl -s get.sdkman.io | bashThanks for using... SSSSSSSSSSSSSSS DDDDDDDDDDDDD KKKKKKKKK KKKKKKK SS:::::::::::::::SD::::::::::::DDD K:::::::K K:::::K S:::::SSSSSS::::::SD:::::::::::::::DD K:::::::K K:::::K S:::::S SSSSSSSDDD:::::DDDDD:::::D K:::::::K K::::::K S:::::S D:::::D D:::::DKK::::::K K:::::KKK S:::::S D:::::D D:::::D K:::::K K:::::K S::::SSSS D:::::D D:::::D K::::::K:::::K SS::::::SSSSS D:::::D D:::::D K:::::::::::K SSS::::::::SS D:::::D D:::::D K:::::::::::K SSSSSS::::S D:::::D D:::::D K::::::K:::::K S:::::S D:::::D D:::::D K:::::K K:::::K S:::::S D:::::D D:::::DKK::::::K K:::::KKK SSSSSSS S:::::SDDD:::::DDDDD:::::D K:::::::K K::::::K S::::::SSSSSS:::::SD:::::::::::::::DD K:::::::K K:::::K S:::::::::::::::SS D::::::::::::DDD K:::::::K K:::::K SSSSSSSSSSSSSSS DDDDDDDDDDDDD KKKKKKKKK KKKKKKK mmmmmmm mmmmmmm aaaaaaaaaaaaa nnnn nnnnnnnn mm:::::::m m:::::::mm a::::::::::::a n:::nn::::::::nn m::::::::::mm::::::::::m aaaaaaaaa:::::an::::::::::::::nn m::::::::::::::::::::::m a::::ann:::::::::::::::n m:::::mmm::::::mmm:::::m aaaaaaa:::::a n:::::nnnn:::::n m::::m m::::m m::::m aa::::::::::::a n::::n n::::n m::::m m::::m m::::m a::::aaaa::::::a n::::n n::::n m::::m m::::m m::::ma::::a a:::::a n::::n n::::n m::::m m::::m m::::ma::::a a:::::a n::::n n::::n m::::m m::::m m::::ma:::::aaaa::::::a n::::n n::::n m::::m m::::m m::::m a::::::::::aa:::a n::::n n::::n mmmmmm mmmmmm mmmmmm aaaaaaaaaa aaaa nnnnnn nnnnnn Now attempting installation...Looking for a previous installation of SDKMAN...Looking for unzip...Looking for curl...Looking for sed...Installing SDKMAN scripts...Create distribution directories...Create candidate directories...Created for asciidoctorj: /root/.sdkman/asciidoctorjCreated for crash: /root/.sdkman/crashCreated for gaiden: /root/.sdkman/gaidenCreated for glide: /root/.sdkman/glideCreated for gradle: /root/.sdkman/gradleCreated for grails: /root/.sdkman/grailsCreated for griffon: /root/.sdkman/griffonCreated for groovy: /root/.sdkman/groovyCreated for groovyserv: /root/.sdkman/groovyservCreated for jbake: /root/.sdkman/jbakeCreated for jbossforge: /root/.sdkman/jbossforgeCreated for lazybones: /root/.sdkman/lazybonesCreated for springboot: /root/.sdkman/springbootPrime the config file...Download script archive...Extract script archive...Install scripts...Attempt update of bash profiles...Updated existing /root/.profileUpdated existing /root/.bashrcAttempt update of zsh profiles...Created and initialised /root/.zshrcAll done!Please open a new terminal, or run the following in the existing one: source "/root/.sdkman/bin/sdkman-init.sh"Then issue the following command: sdk helpEnjoy!!!
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
安装完成后需要初始化sdkman:
# source "$HOME/.sdkman/bin/sdkman-init.sh"
- 1
一旦sdkman可用,那么安装Gradle就极其简单了:
# sdk install gradle==== BROADCAST =================================================================* 30/09/15: Gradle 2.8-rc-1 released on SDKMAN! #gradle* 30/09/15: SDKMAN! 3.0.5 released. Fixes issue #363. http://bit.ly/1KRSKey* 25/09/15: Grails 3.0.8 released on SDKMAN! #grailsfw================================================================================Downloading: gradle 2.7 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 354 0 0 28 0 --:--:-- 0:00:12 --:--:-- 83100 42.7M 100 42.7M 0 0 87103 0 0:08:34 0:08:34 --:--:-- 113kInstalling: gradle 2.7Done installing!Do you want gradle 2.7 to be set as default? (Y/n): ySetting gradle 2.7 as default.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
下面可以开始创建构建脚本。首先要做的是创建一个名为settings.gradle的文件,设置项目名。
rootProject.name = 'my-javaee'
- 1
此文件适用于多模块的项目。
下面需要创建一个名为build.gradle的配置文件,它负责管理所有的构建过程。
apply plugin: 'war'group = 'org.superbiz'version = '1.0-SNAPSHOT'description = "My JavaEE project"sourceCompatibility = 1.8targetCompatibility = 1.8repositories { mavenCentral() }dependencies { providedCompile group: 'javax', name: 'javaee-api', version:'7.0'}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
注意,第一行指示构建的是一个Web项目(WAR包)。接着是项目的属性,如项目组group、版本version、描述description、Java编译器的版本、软件仓库。只有最后一行的依赖关系是必须的,它提供了构建的处理范围。
要注意,如果使用的是war插件,那么providedCompile仅有一个是有效的。如果使用的是像java这样的插件,那么需要自己实现这个函数。
可以看出,Gradle的配置文件更加精炼,没有冗余的信息。想深入Gradle就继续吧!
给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/2e19ffb3303a490d20ea5d00dd397156.gif)