Code review comment: @glefloch can you think of a trick to make `quarkusGenerateCodeDev` run only when the intention is to launch the dev mode? Perhaps, the task can be disabled by default and enabled by the `quarkusDev` somehow?

Code before review:
private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
TaskContainer tasks = project.getTasks();
tasks.create(LIST_EXTENSIONS_TASK_NAME, QuarkusListExtensions.class);
tasks.create(LIST_CATEGORIES_TASK_NAME, QuarkusListCategories.class);
tasks.create(LIST_PLATFORMS_TASK_NAME, QuarkusListPlatforms.class);
tasks.create(ADD_EXTENSION_TASK_NAME, QuarkusAddExtension.class);
tasks.create(REMOVE_EXTENSION_TASK_NAME, QuarkusRemoveExtension.class);
QuarkusGenerateCode quarkusGenerateCode = tasks.create(QUARKUS_GENERATE_CODE_TASK_NAME, QuarkusGenerateCode.class);
QuarkusGenerateCode quarkusGenerateCodeDev = tasks.create(QUARKUS_GENERATE_CODE_DEV_TASK_NAME,
QuarkusGenerateCode.class);
quarkusGenerateCodeDev.setDevMode(true);
QuarkusGenerateCode quarkusGenerateCodeTests = tasks.create(QUARKUS_GENERATE_CODE_TESTS_TASK_NAME,
QuarkusGenerateCode.class);
quarkusGenerateCodeTests.setTest(true);
Task quarkusBuild = tasks.create(QUARKUS_BUILD_TASK_NAME, QuarkusBuild.class);
quarkusBuild.dependsOn(quarkusGenerateCode);
QuarkusDev quarkusDev = tasks.create(QUARKUS_DEV_TASK_NAME, QuarkusDev.class);
Task quarkusRemoteDev = tasks.create(QUARKUS_REMOTE_DEV_TASK_NAME, QuarkusRemoteDev.class);
Task quarkusTest = tasks.create(QUARKUS_TEST_TASK_NAME, QuarkusTest.class);
tasks.create(QUARKUS_TEST_CONFIG_TASK_NAME, QuarkusTestConfig.class);
Task buildNative = tasks.create(BUILD_NATIVE_TASK_NAME, DefaultTask.class);
buildNative.finalizedBy(quarkusBuild);
buildNative.doFirst(t -> project.getLogger()
.warn("The 'buildNative' task has been deprecated in favor of 'build -Dquarkus.package.type=native'"));
configureBuildNativeTask(project);
final Consumer<Test> configureTestTask = t -> {
t.doFirst(new Action<Task>() {
@Override
public void execute(Task test) {
quarkusExt.beforeTest(t);
}
});
t.useJUnitPlatform();
quarkusBuild.shouldRunAfter(t);
};
project.getPlugins().withType(
BasePlugin.class,
basePlugin -> tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(quarkusBuild));
project.getPlugins().withType(
JavaPlugin.class,
javaPlugin -> {
project.afterEvaluate(this::afterEvaluate);
ConfigurationContainer configurations = project.getConfigurations();
JavaCompile compileJavaTask = (JavaCompile) tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);
compileJavaTask.mustRunAfter(quarkusGenerateCodeDev);
compileJavaTask.mustRunAfter(quarkusGenerateCode);
JavaCompile compileTestJavaTask = (JavaCompile) tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
compileTestJavaTask.dependsOn(quarkusGenerateCodeTests);
Task classesTask = tasks.getByName(JavaPlugin.CLASSES_TASK_NAME);
Task resourcesTask = tasks.getByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME);
Task testClassesTask = tasks.getByName(JavaPlugin.TEST_CLASSES_TASK_NAME);
Task testResourcesTask = tasks.getByName(JavaPlugin.PROCESS_TEST_RESOURCES_TASK_NAME);
quarkusGenerateCode.dependsOn(resourcesTask);
quarkusGenerateCodeDev.dependsOn(resourcesTask);
quarkusGenerateCodeTests.dependsOn(resourcesTask);
quarkusDev.dependsOn(classesTask, resourcesTask, testClassesTask, testResourcesTask, quarkusGenerateCodeDev,
quarkusGenerateCodeTests);
quarkusRemoteDev.dependsOn(classesTask, resourcesTask);
quarkusTest.dependsOn(classesTask, resourcesTask, testClassesTask, testResourcesTask, quarkusGenerateCode,
quarkusGenerateCodeTests);
quarkusBuild.dependsOn(classesTask, resourcesTask, tasks.getByName(JavaPlugin.JAR_TASK_NAME));
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets();
SourceSet nativeTestSourceSet = sourceSets.create(NATIVE_TEST_SOURCE_SET_NAME);
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
quarkusGenerateCode.setSourcesDirectories(getSourcesParents(mainSourceSet));
quarkusGenerateCodeDev.setSourcesDirectories(getSourcesParents(mainSourceSet));
quarkusGenerateCodeTests.setSourcesDirectories(getSourcesParents(testSourceSet));
nativeTestSourceSet.setCompileClasspath(
nativeTestSourceSet.getCompileClasspath()
.plus(mainSourceSet.getOutput())
.plus(testSourceSet.getOutput()));
nativeTestSourceSet.setRuntimeClasspath(
nativeTestSourceSet.getRuntimeClasspath()
.plus(mainSourceSet.getOutput())
.plus(testSourceSet.getOutput()));
configurations.create(DEV_MODE_CONFIGURATION_NAME);
configurations.maybeCreate(NATIVE_TEST_IMPLEMENTATION_CONFIGURATION_NAME)
.extendsFrom(configurations.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME));
configurations.maybeCreate(NATIVE_TEST_RUNTIME_ONLY_CONFIGURATION_NAME)
.extendsFrom(configurations.findByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME));
Task testNative = tasks.create(TEST_NATIVE_TASK_NAME, QuarkusTestNative.class);
testNative.dependsOn(quarkusBuild);
testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName(JavaPlugin.TEST_TASK_NAME)));
tasks.withType(Test.class).forEach(configureTestTask);
tasks.withType(Test.class).whenTaskAdded(configureTestTask::accept);
SourceSet generatedSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES);
SourceSet generatedTestSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES);
for (String provider : QuarkusGenerateCode.CODE_GENERATION_PROVIDER) {
mainSourceSet.getJava().srcDir(
new File(generatedSourceSet.getJava().getClassesDirectory().get().getAsFile(), provider));
testSourceSet.getJava().srcDir(
new File(generatedTestSourceSet.getJava().getClassesDirectory().get().getAsFile(), provider));
}
configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)
.getResolutionStrategy().eachDependency(d -> {
if ("quarkus-panache-common".equals(d.getTarget().getName())
&& "io.quarkus".equals(d.getTarget().getGroup())) {
project.getDependencies().add("annotationProcessor", d.getRequested().getGroup() + ":"
+ d.getRequested().getName() + ":" + d.getRequested().getVersion());
}
});
});
project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> {
quarkusDev.shouldPropagateJavaCompilerArgs(false);
tasks.getByName("compileKotlin").mustRunAfter(quarkusGenerateCode);
tasks.getByName("compileKotlin").mustRunAfter(quarkusGenerateCodeDev);
tasks.getByName("compileTestKotlin").dependsOn(quarkusGenerateCodeTests);
});
}

Line under review: compileJavaTask.mustRunAfter(quarkusGenerateCode);

Code after addressing the review:
private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {
TaskContainer tasks = project.getTasks();
tasks.create(LIST_EXTENSIONS_TASK_NAME, QuarkusListExtensions.class);
tasks.create(LIST_CATEGORIES_TASK_NAME, QuarkusListCategories.class);
tasks.create(LIST_PLATFORMS_TASK_NAME, QuarkusListPlatforms.class);
tasks.create(ADD_EXTENSION_TASK_NAME, QuarkusAddExtension.class);
tasks.create(REMOVE_EXTENSION_TASK_NAME, QuarkusRemoveExtension.class);
QuarkusGenerateCode quarkusGenerateCode = tasks.create(QUARKUS_GENERATE_CODE_TASK_NAME, QuarkusGenerateCode.class);
QuarkusGenerateCode quarkusGenerateCodeDev = tasks.create(QUARKUS_GENERATE_CODE_DEV_TASK_NAME,
QuarkusGenerateCode.class);
quarkusGenerateCodeDev.setDevMode(true);
QuarkusGenerateCode quarkusGenerateCodeTests = tasks.create(QUARKUS_GENERATE_CODE_TESTS_TASK_NAME,
QuarkusGenerateCode.class);
quarkusGenerateCodeTests.setTest(true);
Task quarkusBuild = tasks.create(QUARKUS_BUILD_TASK_NAME, QuarkusBuild.class);
quarkusBuild.dependsOn(quarkusGenerateCode);
QuarkusDev quarkusDev = tasks.create(QUARKUS_DEV_TASK_NAME, QuarkusDev.class);
Task quarkusRemoteDev = tasks.create(QUARKUS_REMOTE_DEV_TASK_NAME, QuarkusRemoteDev.class);
Task quarkusTest = tasks.create(QUARKUS_TEST_TASK_NAME, QuarkusTest.class);
tasks.create(QUARKUS_TEST_CONFIG_TASK_NAME, QuarkusTestConfig.class);
Task buildNative = tasks.create(BUILD_NATIVE_TASK_NAME, DefaultTask.class);
buildNative.finalizedBy(quarkusBuild);
buildNative.doFirst(t -> project.getLogger()
.warn("The 'buildNative' task has been deprecated in favor of 'build -Dquarkus.package.type=native'"));
configureBuildNativeTask(project);
final Consumer<Test> configureTestTask = t -> {
t.doFirst(new Action<Task>() {
@Override
public void execute(Task test) {
quarkusExt.beforeTest(t);
}
});
t.useJUnitPlatform();
quarkusBuild.shouldRunAfter(t);
};
project.getPlugins().withType(
BasePlugin.class,
basePlugin -> tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(quarkusBuild));
project.getPlugins().withType(
JavaPlugin.class,
javaPlugin -> {
project.afterEvaluate(this::afterEvaluate);
ConfigurationContainer configurations = project.getConfigurations();
JavaCompile compileJavaTask = (JavaCompile) tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);
compileJavaTask.mustRunAfter(quarkusGenerateCodeDev);
compileJavaTask.mustRunAfter(quarkusGenerateCode);
JavaCompile compileTestJavaTask = (JavaCompile) tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
compileTestJavaTask.dependsOn(quarkusGenerateCodeTests);
Task classesTask = tasks.getByName(JavaPlugin.CLASSES_TASK_NAME);
Task resourcesTask = tasks.getByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME);
Task testClassesTask = tasks.getByName(JavaPlugin.TEST_CLASSES_TASK_NAME);
Task testResourcesTask = tasks.getByName(JavaPlugin.PROCESS_TEST_RESOURCES_TASK_NAME);
quarkusGenerateCode.dependsOn(resourcesTask);
quarkusGenerateCodeDev.dependsOn(resourcesTask);
quarkusGenerateCodeTests.dependsOn(resourcesTask);
quarkusDev.dependsOn(classesTask, resourcesTask, testClassesTask, testResourcesTask, quarkusGenerateCodeDev,
quarkusGenerateCodeTests);
quarkusRemoteDev.dependsOn(classesTask, resourcesTask);
quarkusTest.dependsOn(classesTask, resourcesTask, testClassesTask, testResourcesTask, quarkusGenerateCode,
quarkusGenerateCodeTests);
quarkusBuild.dependsOn(classesTask, resourcesTask, tasks.getByName(JavaPlugin.JAR_TASK_NAME));
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
.getSourceSets();
SourceSet nativeTestSourceSet = sourceSets.create(NATIVE_TEST_SOURCE_SET_NAME);
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
quarkusGenerateCode.setSourcesDirectories(getSourcesParents(mainSourceSet));
quarkusGenerateCodeDev.setSourcesDirectories(getSourcesParents(mainSourceSet));
quarkusGenerateCodeTests.setSourcesDirectories(getSourcesParents(testSourceSet));
nativeTestSourceSet.setCompileClasspath(
nativeTestSourceSet.getCompileClasspath()
.plus(mainSourceSet.getOutput())
.plus(testSourceSet.getOutput()));
nativeTestSourceSet.setRuntimeClasspath(
nativeTestSourceSet.getRuntimeClasspath()
.plus(mainSourceSet.getOutput())
.plus(testSourceSet.getOutput()));
configurations.create(DEV_MODE_CONFIGURATION_NAME);
configurations.maybeCreate(NATIVE_TEST_IMPLEMENTATION_CONFIGURATION_NAME)
.extendsFrom(configurations.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME));
configurations.maybeCreate(NATIVE_TEST_RUNTIME_ONLY_CONFIGURATION_NAME)
.extendsFrom(configurations.findByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME));
Task testNative = tasks.create(TEST_NATIVE_TASK_NAME, QuarkusTestNative.class);
testNative.dependsOn(quarkusBuild);
testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName(JavaPlugin.TEST_TASK_NAME)));
tasks.withType(Test.class).forEach(configureTestTask);
tasks.withType(Test.class).whenTaskAdded(configureTestTask::accept);
SourceSet generatedSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES);
SourceSet generatedTestSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES);
for (String provider : QuarkusGenerateCode.CODE_GENERATION_PROVIDER) {
mainSourceSet.getJava().srcDir(
new File(generatedSourceSet.getJava().getClassesDirectory().get().getAsFile(), provider));
testSourceSet.getJava().srcDir(
new File(generatedTestSourceSet.getJava().getClassesDirectory().get().getAsFile(), provider));
}
configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)
.getResolutionStrategy().eachDependency(d -> {
if ("quarkus-panache-common".equals(d.getTarget().getName())
&& "io.quarkus".equals(d.getTarget().getGroup())) {
project.getDependencies().add("annotationProcessor", d.getRequested().getGroup() + ":"
+ d.getRequested().getName() + ":" + d.getRequested().getVersion());
}
});
});
project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> {
quarkusDev.shouldPropagateJavaCompilerArgs(false);
tasks.getByName("compileKotlin").mustRunAfter(quarkusGenerateCode);
tasks.getByName("compileKotlin").mustRunAfter(quarkusGenerateCodeDev);
tasks.getByName("compileTestKotlin").dependsOn(quarkusGenerateCodeTests);
});
}