Skip to content

Commit

Permalink
Revert "Reduce the scope of the dependency resolution strategy to jus…
Browse files Browse the repository at this point in the history
…t the jooqGenerator configuration"

This reverts commit 423d905.
  • Loading branch information
etiennestuder committed Dec 26, 2023
1 parent 423d905 commit 77e0aee
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<JooqGenerate> jooq = project.getTasks().register(taskName, JooqGenerate.class, config, jooqGeneratorRuntimeConfiguration, project.getExtensions());
TaskProvider<JooqGenerate> 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");
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String> 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);
}
})
);
}

}

0 comments on commit 77e0aee

Please sign in to comment.