Skip to content

Commit

Permalink
Reduce the scope of the dependency resolution strategy to just the jo…
Browse files Browse the repository at this point in the history
…oqGenerator configuration
  • Loading branch information
etiennestuder committed Dec 26, 2023
1 parent d9dc6ac commit 423d905
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/main/groovy/nu/studer/gradle/jooq/JooqPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ 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, jooqExtension);
Configuration jooqGeneratorRuntimeConfiguration = createJooqGeneratorRuntimeConfiguration(project, jooqExtension);

// use the configured jOOQ version and edition on all jOOQ dependencies
enforceJooqEditionAndVersion(jooqGeneratorRuntimeConfiguration, 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, runtimeConfiguration, project.getExtensions());
TaskProvider<JooqGenerate> jooq = project.getTasks().register(taskName, JooqGenerate.class, config, jooqGeneratorRuntimeConfiguration, 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 @@ -58,9 +61,6 @@ 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,20 +89,18 @@ private static Configuration createJooqGeneratorRuntimeConfiguration(Project pro
}

/**
* Forces the jOOQ version and edition selected by the user throughout all dependency configurations.
* Forces the jOOQ version and edition selected by the user on the given configuration.
*/
private static void enforceJooqEditionAndVersion(Project project, JooqExtension jooqExtension) {
private static void enforceJooqEditionAndVersion(Configuration configuration, JooqExtension jooqExtension) {
Set<String> jooqGroupIds = Arrays.stream(JooqEdition.values()).map(JooqEdition::getGroupId).collect(Collectors.toSet());
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);
}
})
);
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 423d905

Please sign in to comment.