前述:
Gradle存在很长时间了,以前只知道Maven和ivy ,最近才知道有这个存在,因为以后要用这个了; 所以,要先学会怎么用这个工具,就从建立一个简单工程开始!
实际上以前是见过Gradle的,只是没注意,当然没注意的还有许多,看图:
原来还有这么多的依赖管理工具!
使用工具:
IDE: eclipse
JDK: 1.7
Gradle: 3.0
SpringBoot
具体步骤:
1、Eclipse添加Gradle支持:
安装Eclipse BulidShip插件:Eclipse-->Help-->Eclipse Marketpalce--->搜索gradle
2、官网下载gradle-3.0-bin.zip备用;
3、Eclipse新建Project选择Gradle,可以选择默认选项,亦可以配置自己的gradlehome
4、修改build.gradle配置文件,添加依赖
apply plugin: ‘java‘ apply plugin: ‘maven‘ apply plugin: ‘maven-publish‘ sourceCompatibility = 1.7 compileJava.options.encoding = ‘UTF-8‘ version = ‘1.0‘ repositories { jcenter() maven { name ‘Maven Repository‘ url "${repositoryMavenUrl}" } ivy { name ‘Ivy Repository‘ url "${repositoryIvyUrl}" layout "pattern", { artifact ‘[organisation]/[module]/[revision]/[type]s/[artifact]-[revision].[ext]‘ ivy ‘[organisation]/[module]/[revision]/[type]s/[artifact].[ext]‘ m2compatible = true } } } dependencies { compile ‘org.slf4j:slf4j-api:1.7.21‘ compile("org.springframework.boot:spring-boot-starter-web:1.4.2.RELEASE") } task copyJars(type: Copy) { from configurations.runtime into ‘build/libs/lib‘ } task copyConfigs(type: Copy) { /* from ‘configs/‘ into ‘build/libs/configs‘ */ } task generateJar(type: Jar, dependsOn: [copyJars, copyConfigs, jar]) { manifest { attributes (‘Implementation-Title‘: ‘Gradle‘, ‘Implementation-Version‘: version, ‘Main-Class‘: ‘sample.main.Main‘, ‘Class-Path‘: configurations.compile.collect {‘lib/‘ + it.getName()}.join(‘ ‘) ) } into(‘‘) { from "$buildDir/classes/main" include(‘sample/‘) } into(‘‘) { from "$projectDir/src/main/resources" } }
build.gradle
repositories配置仓库,默认jcenter(),当然也可以在这里面配置本地服务器的依赖;
5、Spring Boot相关配置,参考:http://www.cnblogs.com/liangblog/p/5207855.html
----------------------------------------------------------------------------------------------------
时间: 2024-10-21 19:20:09