Skip to content

Commit

Permalink
Use Provider API to set edition/version of codegen dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennestuder committed Dec 26, 2023
1 parent 4602d28 commit d9dc6ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void apply(Project project) {
JooqExtension jooqExtension = project.getExtensions().create("jooq", JooqExtension.class);

// create configuration for the runtime classpath of the jooq code generator (shared by all jooq configuration domain objects)
final Configuration runtimeConfiguration = createJooqGeneratorRuntimeConfiguration(project);
final Configuration runtimeConfiguration = createJooqGeneratorRuntimeConfiguration(project, jooqExtension);

// create a jooq task for each jooq configuration domain object
jooqExtension.getConfigurations().configureEach(config -> {
Expand Down Expand Up @@ -80,10 +80,11 @@ private SourceSetContainer getSourceSetsDeprecated(Project project) {
* Adds the configuration that holds the classpath to use for invoking jOOQ. Users can add their JDBC driver and any generator extensions they might have. Explicitly add JAXB
* dependencies since they have been removed from JDK 9 and higher. Explicitly add Activation dependency since it has been removed from JDK 11 and higher.
*/
private static Configuration createJooqGeneratorRuntimeConfiguration(Project project) {
private static Configuration createJooqGeneratorRuntimeConfiguration(Project project, JooqExtension jooqExtension) {
Configuration jooqGeneratorRuntime = project.getConfigurations().create("jooqGenerator");
jooqGeneratorRuntime.setDescription("The classpath used to invoke the jOOQ code generator. Add your JDBC driver, generator extensions, and additional dependencies here.");
project.getDependencies().add(jooqGeneratorRuntime.getName(), "org.jooq:jooq-codegen");
project.getDependencies().addProvider(jooqGeneratorRuntime.getName(),
jooqExtension.getEdition().map(e -> e.getGroupId() + ":jooq-codegen").flatMap(ga -> jooqExtension.getVersion().map(v -> ga + ":" + v)));
return jooqGeneratorRuntime;
}

Expand Down
20 changes: 10 additions & 10 deletions src/test/groovy/nu/studer/gradle/jooq/JooqFuncTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ afterEvaluate {
def result = runWithArguments('dependencies', '--configuration', 'jooqGenerator')

then:
result.output.contains('org.jooq:jooq-codegen -> 3.19.1')
result.output.contains('org.jooq:jooq-codegen:3.19.1')
result.output.contains('org.jooq:jooq:3.19.1')

when:
result = runWithArguments('dependencies', '--configuration', 'compileClasspath')

then:
!result.output.contains('org.jooq:jooq-codegen -> 3.19.1')
!result.output.contains('org.jooq:jooq-codegen:3.19.1')
result.output.contains('org.jooq:jooq:3.19.1')
}

Expand All @@ -254,14 +254,14 @@ afterEvaluate {
def result = runWithArguments('dependencies', '--configuration', 'jooqGenerator')

then:
result.output.contains('org.jooq:jooq-codegen -> 3.16.1')
result.output.contains('org.jooq:jooq-codegen:3.16.1')
result.output.contains('org.jooq:jooq:3.16.1')

when:
result = runWithArguments('dependencies', '--configuration', 'compileClasspath')

then:
!result.output.contains('org.jooq:jooq-codegen -> 3.16.1')
!result.output.contains('org.jooq:jooq-codegen:3.16.1')
result.output.contains('org.jooq:jooq:3.16.1')
}

Expand All @@ -276,14 +276,14 @@ jooq.version = '3.17.1'
def result = runWithArguments('dependencies', '--configuration', 'jooqGenerator')

then:
result.output.contains('org.jooq:jooq-codegen -> 3.17.1')
result.output.contains('org.jooq:jooq-codegen:3.17.1')
result.output.contains('org.jooq:jooq:3.17.1')

when:
result = runWithArguments('dependencies', '--configuration', 'compileClasspath')

then:
!result.output.contains('org.jooq:jooq-codegen -> 3.17.1')
!result.output.contains('org.jooq:jooq-codegen:3.17.1')
result.output.contains('org.jooq:jooq:3.17.1')
}

Expand All @@ -295,14 +295,14 @@ jooq.version = '3.17.1'
def result = runWithArguments('dependencies', '--configuration', 'jooqGenerator')

then: // resolution (incl. transitive dependencies) fails since the trial artifact is not in a public repository
result.output.contains('org.jooq:jooq-codegen -> org.jooq.trial:jooq-codegen:3.19.1 FAILED')
result.output.contains('org.jooq.trial:jooq-codegen:3.19.1 FAILED')
!result.output.contains('org.jooq.trial:jooq:3.19.1')

when:
result = runWithArguments('dependencies', '--configuration', 'compileClasspath')

then:
!result.output.contains('org.jooq:jooq-codegen -> org.jooq.trial:jooq-codegen:3.19.1')
!result.output.contains('org.jooq.trial:jooq-codegen:3.19.1')
result.output.contains('org.jooq.trial:jooq:3.19.1 FAILED')
}

Expand All @@ -316,14 +316,14 @@ jooq.edition = nu.studer.gradle.jooq.JooqEdition.PRO
def result = runWithArguments('dependencies', '--configuration', 'jooqGenerator')

then: // resolution (incl. transitive dependencies) fails since the pro artifact is not in a public repository
result.output.contains('org.jooq:jooq-codegen -> org.jooq.pro:jooq-codegen:3.19.1 FAILED')
result.output.contains('org.jooq.pro:jooq-codegen:3.19.1 FAILED')
!result.output.contains('org.jooq.pro:jooq:3.19.1')

when:
result = runWithArguments('dependencies', '--configuration', 'compileClasspath')

then:
!result.output.contains('org.jooq:jooq-codegen -> org.jooq.pro:jooq-codegen:3.19.1')
!result.output.contains('org.jooq.pro:jooq-codegen:3.19.1')
result.output.contains('org.jooq.pro:jooq:3.19.1 FAILED')
}

Expand Down

0 comments on commit d9dc6ac

Please sign in to comment.