1、工程结构:
--test_gradle
--subProj1
--subProj2
2.build.gradle:
group 'groupid'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'org.springframework', name: 'spring-core', version: '4.3.3.RELEASE'
compile project(':subproj1')
compile project(':subproj2')
}
compileJava.options.encoding = 'UTF-8'
version = '1.0'
ext.author = 'fuxg'
//清除上次的编译过的文件
task clear(type: Delete) {
delete 'build', 'target'
}
jar {
manifest {
attributes('Implementation-Title': 'Gradle',
'Implementation-Version': version,
'Created-By': author,
'Main-Class': 'com.fuxg.Test2',
'Class-Path': configurations.compile.collect { 'lib/' + it.getName() }.join(' ')
)
}
}
//把JAR复制到目标目录
task release(type: Copy, dependsOn: [clear, jar]) {
from(configurations.runtime) {
into 'lib'
}
from('build/resources/main') {
into 'conf'
}
from 'build/libs'
into 'target'
}
3.settings.xml
rootProject.name = 'test_gradle'
include 'subproj1'
include 'subproj2'