build.gradle 在子项目中生成的 jar 是空的



我有以下项目结构:

└───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个项目目录:libserverclient他们有一个包含另外两个目录的构建目录:libstmptmp只有一个文件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

相关内容

  • 没有找到相关文章

最新更新