I have the following project structure:
└───src
└───main
└───java
├───client
├───lib
└───server
I want to generate 2 jar archives with gradle. One jar archive for server
and one jar archive for client
. Both projects depend on lib
.
My settings.gradle
looks like this:
include 'client', 'lib', 'server'
rootProject.name = 'rmi-tutorial'
My build.gradle
looks like this:
subprojects {
apply plugin: 'java'
apply plugin: 'application'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.12'
}
}
The build.gradle
file in src/main/java/client/build.gradle
looks like this:
dependencies {
compile project(':lib')
}
mainClassName = 'client.ComputePi'
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'client.ComputePi'
)
}
}
The build.gradle
file in /src/main/java/server/
looks like this:
dependencies {
compile project(':lib')
}
mainClassName = 'server.ClientEngine'
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'server.ComputeEngine'
)
}
}
There is no build.gradle
in /src/main/java/lib
When I run the task jar
i get the following output:
Working Directory: C:\Users\cre13\workspace\rmi-tutorial
Gradle User Home: C:\Users\cre13\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 3.0
Java Home: C:\Program Files\Java\jdk1.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
After this build process I have a bin directory with all class files and build.gradle files and I have 3 project directories: lib
,server
,client
they have a build directory with two other directories: libs
and tmp
in tmp
there is just a file jar/MANIFEST.MF
that looks like this:
Manifest-Version: 1.0
In the lib
-directory there is a jar archive that is 1KB big. When i extract the jar archive there is inside just the MANIFEST.MF
file from tmp
.
When I invoke the gradle task projects
i get the following structure:
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
You should use a different project structure:
lib
src/main/java
build.gradle
server
src/main/java
build.gradle
client
src/main/java
build.gradle
build.gradle
settings.gradle