diff --git a/src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java b/src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java index ec600af9..aab695e9 100644 --- a/src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java +++ b/src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java @@ -37,15 +37,12 @@ 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) - Configuration jooqGeneratorRuntimeConfiguration = createJooqGeneratorRuntimeConfiguration(project, jooqExtension); - - // use the configured jOOQ version and edition on all jOOQ dependencies - enforceJooqEditionAndVersion(jooqGeneratorRuntimeConfiguration, jooqExtension); + final Configuration runtimeConfiguration = createJooqGeneratorRuntimeConfiguration(project, jooqExtension); // create a jooq task for each jooq configuration domain object jooqExtension.getConfigurations().configureEach(config -> { String taskName = "generate" + (config.name.equals("main") ? "" : capitalize(config.name)) + "Jooq"; - TaskProvider jooq = project.getTasks().register(taskName, JooqGenerate.class, config, jooqGeneratorRuntimeConfiguration, project.getExtensions()); + TaskProvider jooq = project.getTasks().register(taskName, JooqGenerate.class, config, runtimeConfiguration, project.getExtensions()); jooq.configure(task -> { task.setDescription(String.format("Generates the jOOQ sources from the %s jOOQ configuration.", config.name)); task.setGroup("jOOQ"); @@ -61,6 +58,9 @@ public void apply(Project project) { } }); }); + + // use the configured jOOQ version and edition on all jOOQ dependencies + enforceJooqEditionAndVersion(project, jooqExtension); } private SourceSetContainer getSourceSets(Project project) { @@ -89,18 +89,20 @@ private static Configuration createJooqGeneratorRuntimeConfiguration(Project pro } /** - * Forces the jOOQ version and edition selected by the user on the given configuration. + * Forces the jOOQ version and edition selected by the user throughout all dependency configurations. */ - private static void enforceJooqEditionAndVersion(Configuration configuration, JooqExtension jooqExtension) { + private static void enforceJooqEditionAndVersion(Project project, JooqExtension jooqExtension) { Set jooqGroupIds = Arrays.stream(JooqEdition.values()).map(JooqEdition::getGroupId).collect(Collectors.toSet()); - configuration.getResolutionStrategy().eachDependency(details -> { - ModuleVersionSelector requested = details.getRequested(); - if (jooqGroupIds.contains(requested.getGroup()) && requested.getName().startsWith("jooq")) { - String group = jooqExtension.getEdition().get().getGroupId(); - String version = jooqExtension.getVersion().get(); - details.useTarget(group + ":" + requested.getName() + ":" + version); - } - }); + project.getConfigurations().configureEach(configuration -> + configuration.getResolutionStrategy().eachDependency(details -> { + ModuleVersionSelector requested = details.getRequested(); + if (jooqGroupIds.contains(requested.getGroup()) && requested.getName().startsWith("jooq")) { + String group = jooqExtension.getEdition().get().getGroupId(); + String version = jooqExtension.getVersion().get(); + details.useTarget(group + ":" + requested.getName() + ":" + version); + } + }) + ); } }