Ken Liu
Ken Liu

Reputation: 22914

Gradle: how do I configure the jar location to be in the parent directory of the project?

I'm trying to build a Gradle JAR project that is a subproject of another and would like the output JAR file to be in a parent directory (to be specific in the "lib" directory of the parent, or sibling). How do I configure Gradle for this and where is this documented?

Upvotes: 11

Views: 20938

Answers (2)

Ken Liu
Ken Liu

Reputation: 22914

In build.gradle, add:

libsDirName = '../../lib'

The config settings are shown in the official Gradle docs for the java plugin.

BTW, I fully agree with the intent behind the comments and answers given by Peter and Hiery, but sometimes the simplest solution is the best one.

Upvotes: 22

Hiery Nomus
Hiery Nomus

Reputation: 17769

Agreed with the comment Peter typed. However I think you want to express that the parent project depends on the output of the submodule. Expressing that and ensuring that the parent copies the output of the submodule to its 'lib' directory makes more sense.

task assembleSubModules(type: Copy) {
  destinationDir = file("lib")

  into("lib") {
    project.subprojects.each { p ->
      from(p.tasks.withType(Jar)*.outputs)
    }
  }
}

Upvotes: 8

Related Questions