1

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
shibumi
  • 77
  • 2
  • 8
  • You should re-read the userguide about multi-project builds. The `build.gradle`s for the sub-projects are not even read, but default empty ones are used, because your directory structure does not match what you configure in `settings.gradle`. – Vampire Jun 22 '17 at 13:08
  • Do you have an example how my project directory should look like? the `settings.gradle` file specifies how it should be. I can't find any hint about the project structure for multi projects here: https://docs.gradle.org/3.3/userguide/intro_multi_project_builds.html the docs just specify how to setup the `settings.gradle` – shibumi Jun 22 '17 at 13:15
  • https://github.com/gradle/oreilly-gradle-book-examples/tree/master/multiproject-individual – Vampire Jun 22 '17 at 13:32

1 Answers1

1

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
larsgrefer
  • 2,735
  • 19
  • 36