diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index 16a7742557386..942515adbefc8 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -136,6 +136,7 @@ public void apply(Project project) { final QuarkusPluginExtension quarkusExt = project.getExtensions().create(EXTENSION_NAME, QuarkusPluginExtension.class, project); + createSourceSets(project); createConfigurations(project); registerTasks(project, quarkusExt); } @@ -323,7 +324,7 @@ public boolean isSatisfiedBy(Task t) { quarkusGenerateCodeDev.configure(task -> task.setSourcesDirectories(getSourcesParents(mainSourceSet))); quarkusGenerateCodeTests.configure(task -> task.setSourcesDirectories(getSourcesParents(testSourceSet))); - SourceSet intTestSourceSet = sourceSets.create(INTEGRATION_TEST_SOURCE_SET_NAME); + SourceSet intTestSourceSet = sourceSets.getByName(INTEGRATION_TEST_SOURCE_SET_NAME); intTestSourceSet.setCompileClasspath( intTestSourceSet.getCompileClasspath() .plus(mainSourceSet.getOutput()) @@ -345,7 +346,7 @@ public boolean isSatisfiedBy(Task t) { intTestTask.setTestClassesDirs(intTestSourceOutputClasses); }); - SourceSet nativeTestSourceSet = sourceSets.create(NATIVE_TEST_SOURCE_SET_NAME); + SourceSet nativeTestSourceSet = sourceSets.getByName(NATIVE_TEST_SOURCE_SET_NAME); nativeTestSourceSet.setCompileClasspath( nativeTestSourceSet.getCompileClasspath() .plus(mainSourceSet.getOutput()) @@ -391,8 +392,8 @@ public void execute(Task task) { // quarkusBuild is expected to run after the project has passed the tests quarkusBuildCacheableAppParts.configure(task -> task.shouldRunAfter(tasks.withType(Test.class))); - SourceSet generatedSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES); - SourceSet generatedTestSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES); + SourceSet generatedSourceSet = sourceSets.getByName(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES); + SourceSet generatedTestSourceSet = sourceSets.getByName(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES); // Register the quarkus-generated-code for (String provider : QuarkusGenerateCode.CODE_GENERATION_PROVIDER) { @@ -423,14 +424,22 @@ private static void configureGenerateCodeTask(QuarkusGenerateCode task, String g task.getGeneratedOutputDirectory().set(generatedSources.getJava().getClassesDirectory().get().getAsFile()); } + private void createSourceSets(Project project) { + SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); + sourceSets.create(INTEGRATION_TEST_SOURCE_SET_NAME); + sourceSets.create(NATIVE_TEST_SOURCE_SET_NAME); + sourceSets.create(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES); + sourceSets.create(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES); + } + private void createConfigurations(Project project) { final ConfigurationContainer configContainer = project.getConfigurations(); // Custom configuration to be used for the dependencies of the testNative task - configContainer.maybeCreate(NATIVE_TEST_IMPLEMENTATION_CONFIGURATION_NAME) + configContainer.getByName(NATIVE_TEST_IMPLEMENTATION_CONFIGURATION_NAME) .extendsFrom(configContainer.findByName(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME)); - configContainer.maybeCreate(NATIVE_TEST_RUNTIME_ONLY_CONFIGURATION_NAME) + configContainer.getByName(NATIVE_TEST_RUNTIME_ONLY_CONFIGURATION_NAME) .extendsFrom(configContainer.findByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME)); // create a custom configuration to be used for the dependencies of the quarkusIntTest task