Gradle: assembling multiple source sets into one jar

I asked the corresponding question here JOOQ and gradle class generation

In this question, I am trying to find a better way to do multi-step assembly, including creating classes in the middle step. I took the β€œOption 2” approach and am now at a dead end.

I have the following build.gradle file

apply plugin: 'java' apply plugin: 'eclipse' sourceSets { bootstrap generated { compileClasspath += bootstrap.output } main { compileClasspath += bootstrap.output compileClasspath += generated.output } } buildscript { repositories { mavenCentral() } dependencies { classpath 'org.jooq:jooq-codegen:3.5.0' classpath 'postgresql:postgresql:9.1-901.jdbc4' classpath project(":") } } dependencies { compile 'org.jooq:jooq:3.5.0' compile 'org.jooq:jooq-codegen:3.5.0' compile 'org.apache.poi:poi:3.10.1' compile 'com.google.guava:guava:18.0' generatedCompile 'org.jooq:jooq:3.5.0' generatedCompile 'org.jooq:jooq-codegen:3.5.0' generatedCompile 'org.apache.poi:poi:3.10.1' generatedCompile 'com.google.guava:guava:18.0' bootstrapCompile 'org.jooq:jooq:3.5.0' bootstrapCompile 'org.jooq:jooq-codegen:3.5.0' bootstrapCompile 'org.apache.poi:poi:3.10.1' bootstrapCompile 'com.google.guava:guava:18.0' } task generate << { //Use JOOQ to generate classes, with the output going into the generated sourceSet .withDirectory(file("src/generated/java").getAbsolutePath()) } generatedClasses { dependsOn bootstrapClasses dependsOn generate } jar { dependsOn generatedClasses dependsOn bootstrapClasses } 

The structure is that

  • The bootstrap source set contains some of the core Java classes needed to generate the code, plus the sql file that will be used to unpack the database
  • Generate task uses classes and sql file in boostrap to generate classes
  • The generated set contains the outputs of the generation task and
  • The original main set contains what can be called "normal" classes (that is, those that use the database described by the bootstrap and generated classes).

I have a couple of problems that I cannot unravel:

  • I seem to have to duplicate dependencies for each source set
  • When a jar file is created, it contains only classes created from the main source set

I should note that the build, as shown above, will successfully generate each of the source sets.

Any help would be greatly appreciated.

+6
source share
1 answer

OK. I think I found the answer to this question. There were two parts ....

The first problem, requiring you to specify the same dependencies several times, was fixed by adding the following:

 configurations { generatedCompile { extendsFrom compile } bootstrapCompile { extendsFrom compile } } 

Second problem: a jar file that does not have all the build artifacts has been fixed by changing the jar task to

 jar { from sourceSets.generated.output from sourceSets.bootstrap.output dependsOn bootstrapClasses dependsOn generatedClasses } 
+8
source

Source: https://habr.com/ru/post/979024/


All Articles