Multiple projects building

Hello, i have and issue about multiple project building. My project structure is:
Project
\lib
\jar1
\jar2

jar1 and jar2 are depends from lib. What i want to do:

  1. Building jar1 must output lib.jar and jar1.jar in \build folder of jar1 project (and accordingly for jar2).
  2. Building Project must output lib.jar, jar1.jar, jar2.jar in \build folder of Project.

How it could be done?

Does this mean jar1 and jar2 depend on lib or are jar1 and jar2 dependants of lib?

Assuming jar1 and 2 depend on lib…
We have something similar going on to this.

settings.gradle:

include 'jar1', 'jar2','Project','lib'

build.gradle

project(':jar1') {
  dependencies {
    compile project(':lib')
  }
}

project(':Project') {
  dependencies {
    compile project(':jar1')
    compile project(':jar2')
  }
}

This only says that Project need jar1 and 2 to compile, and I guess you want to produce some complete binary from Project. If so you can dowload all your runtime deps into Project/build/lib with something like:

task myTask( type: Copy) {
  into("lib") {
    from(jar)
    from(configurations.runtime)
  }
}

This is just a gist of things, and I might have misunderstood you

Thanks for response. I tried to use your suggestion:

with gradlew Project:build, but gradle generated only Project.jar. The point is that i dont need Project.jar at all, I want i want is to split all of my projects to separate files. Expected files after build:
Project\build\lib
lib.jar
jar1.jar
jar2.jar

To be honest with you i came to java world from the c# and trying to repeat things that works there: if i build whole project consist of N subprojects in c# i will get N .dll-files on output. I dont really need to build one mega .dll file with all of my dependencies. How can i perform such scenario?

Sure, that’s the way it’s supposed to work… The .java files in Project/src/main/java (or whereever) is compiled using classes from jar1 project and jar2 project.

If you then want to run some main class in Project all required jars will have to be provided as classpath to the java command (this is always slightly messy).

Let’s say “Project” is a standard java application (aka something with a main-class) that you wish to run at some point I would suggest using the “application” plugin on the “Project” project. That will take care of all this for you…

1 Like