我有以下项目结构:
└───src
└───main
└───java
├───client
├───lib
└───server
我想用 gradle 生成 2 个罐子档案。一个用于server
的罐子存档和一个用于client
的罐子存档。这两个项目都取决于lib
。
我的settings.gradle
如下所示:
include 'client', 'lib', 'server'
rootProject.name = 'rmi-tutorial'
我的build.gradle
如下所示:
subprojects {
apply plugin: 'java'
apply plugin: 'application'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
}
src/main/java/client/build.gradle
中的build.gradle
文件如下所示:
dependencies {
compile project(':lib')
}
mainClassName = 'client.ComputePi'
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'client.ComputePi'
)
}
}
/src/main/java/server/
中的build.gradle
文件如下所示:
dependencies {
compile project(':lib')
}
mainClassName = 'server.ClientEngine'
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'server.ComputeEngine'
)
}
}
/src/main/java/lib
没有build.gradle
当我运行任务jar
时,我得到以下输出:
Working Directory: C:Userscre13workspacermi-tutorial
Gradle User Home: C:Userscre13.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 3.0
Java Home: C:Program FilesJavajdk1.8.0_101
JVM Arguments: None
Program Arguments: None
Gradle Tasks: jar
:client:compileJava UP-TO-DATE
:client:processResources UP-TO-DATE
:client:classes UP-TO-DATE
:client:jar
:lib:compileJava UP-TO-DATE
:lib:processResources UP-TO-DATE
:lib:classes UP-TO-DATE
:lib:jar
:server:compileJava UP-TO-DATE
:server:processResources UP-TO-DATE
:server:classes UP-TO-DATE
:server:jar
BUILD SUCCESSFUL
Total time: 0.107 secs
在此构建过程之后,我有一个包含所有类文件和build.gradle文件的bin目录,我有3个项目目录:lib
,server
,client
他们有一个包含另外两个目录的构建目录:libs
和tmp
tmp
只有一个文件jar/MANIFEST.MF
如下所示:
Manifest-Version: 1.0
在lib
-目录中有一个 1KB 大的 jar 存档。当我提取jar存档时,里面只有tmp
中的MANIFEST.MF
文件。
当我调用 gradle 任务projects
时,我得到以下结构:
Root project 'rmi-tutorial'
+--- Project ':client'
+--- Project ':lib'
--- Project ':server'
To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :client:tasks
BUILD SUCCESSFUL
Total time: 0.055 secs
您应该使用不同的项目结构:
lib
src/main/java
build.gradle
server
src/main/java
build.gradle
client
src/main/java
build.gradle
build.gradle
settings.gradle