From c85aea0bf52e6c37b39f252d9e650c5071a6ad77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Champeau?= Date: Mon, 13 Nov 2023 11:46:34 +0100 Subject: [PATCH] Upgrade to Kotlin plugin 1.9.20 (#864) * Upgrade to Kotlin plugin 1.9.20 * Workaround Kotlin 1.9.20 bug Since Kotlin plugin 1.9.20, kapt tasks are broken if dependencies are added to the KAPT configurations in an `afterEvaluate`. This is precisely what we were doing. Since using `afterEvaluate` is often a code smell (but it wasn't in our case), the proposed solution is to deprecate the use of `additionalSourceSets`, and have an eager configuration of sourceSets instead, as soon as the `sourceSets(...)` method is called. It's a small breaking change, in the sense that if the user had configured the `additionalSourceSets` and later in time decides to remove entries from that list, then this would no longer work. * Make Sonar happier --- .../kotlin/KotlinLibraryFunctionalTest.groovy | 14 +-- .../gradle/graalvm/MicronautGraalPlugin.java | 20 +++- gradle/libs.versions.toml | 4 +- .../gradle/AnnotationProcessing.java | 17 ++- .../micronaut/gradle/MicronautBasePlugin.java | 4 +- .../gradle/MicronautComponentPlugin.java | 53 +++++---- .../micronaut/gradle/MicronautExtension.java | 4 +- .../gradle/MicronautKotlinSupport.java | 105 +++++++++++------- .../micronaut/gradle/SourceSetConfigurer.java | 22 ++++ .../gradle/SourceSetConfigurerRegistry.java | 37 ++++++ .../MicronautDeprecationsPluginSpec.groovy | 82 ++++++++++++++ 11 files changed, 284 insertions(+), 78 deletions(-) create mode 100644 minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurer.java create mode 100644 minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurerRegistry.java create mode 100644 minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy diff --git a/functional-tests/src/test/groovy/io/micronaut/gradle/kotlin/KotlinLibraryFunctionalTest.groovy b/functional-tests/src/test/groovy/io/micronaut/gradle/kotlin/KotlinLibraryFunctionalTest.groovy index f44be948..489c031c 100644 --- a/functional-tests/src/test/groovy/io/micronaut/gradle/kotlin/KotlinLibraryFunctionalTest.groovy +++ b/functional-tests/src/test/groovy/io/micronaut/gradle/kotlin/KotlinLibraryFunctionalTest.groovy @@ -75,7 +75,7 @@ class Foo {} processing { incremental(true) } - } + } ${getRepositoriesBlock('kotlin')} @@ -114,12 +114,12 @@ class Foo {} id("io.micronaut.$plugin") } - sourceSets { - val custom by creating { - compileClasspath += sourceSets["main"].output - runtimeClasspath += sourceSets["main"].output - } - } + val custom by sourceSets.creating + + dependencies { + "customImplementation"(project) + } + micronaut { version("$micronautVersion") processing { diff --git a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java index ae991ec9..bb4dabc9 100644 --- a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java +++ b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java @@ -1,9 +1,11 @@ package io.micronaut.gradle.graalvm; +import io.micronaut.gradle.AnnotationProcessing; import io.micronaut.gradle.MicronautComponentPlugin; import io.micronaut.gradle.MicronautExtension; import io.micronaut.gradle.MicronautRuntime; import io.micronaut.gradle.PluginsHelper; +import io.micronaut.gradle.SourceSetConfigurerRegistry; import io.micronaut.gradle.internal.AutomaticDependency; import org.graalvm.buildtools.gradle.NativeImagePlugin; import org.graalvm.buildtools.gradle.dsl.GraalVMExtension; @@ -14,7 +16,6 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.DependencySet; import org.gradle.api.plugins.ExtensionAware; -import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskContainer; @@ -123,11 +124,22 @@ private void workaroundForResourcesDirectoryMissing(Project project) { } private static void configureAnnotationProcessing(Project project, MicronautExtension extension) { + var registry = project.getExtensions().getByType(SourceSetConfigurerRegistry.class); + var knownSourceSets = new HashSet(); + registry.register(sourceSet -> { + addGraalVMAnnotationProcessorDependency(project, Set.of(sourceSet)); + knownSourceSets.add(sourceSet); + }); var sourceSets = PluginsHelper.findSourceSets(project); project.afterEvaluate(unused -> { - ListProperty sets = extension.getProcessing().getAdditionalSourceSets(); - if (sets.isPresent()) { - addGraalVMAnnotationProcessorDependency(project, sets.get()); + @SuppressWarnings("deprecation") + var sets = extension.getProcessing().getAdditionalSourceSets(); + var additionalSourceSets = sets.get(); + for (SourceSet sourceSet : additionalSourceSets) { + if (!knownSourceSets.contains(sourceSet)) { + AnnotationProcessing.showAdditionalSourceSetDeprecationWarning(sourceSet); + registry.register(sourceSet1 -> addGraalVMAnnotationProcessorDependency(project, Set.of(sourceSet))); + } } }); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d2295ed1..f05d63de 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -kotlin = "1.8.22" -ksp = "1.8.22-1.0.11" +kotlin = "1.9.20" +ksp = "1.9.20-1.0.14" docker = "9.3.3" diffplug = "3.43.0" shadow = "8.1.1" diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java b/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java index 677e5be0..6b4d5d7b 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java @@ -4,6 +4,8 @@ import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.SourceSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; @@ -14,19 +16,27 @@ * @since 1.0.0 */ public class AnnotationProcessing implements AnnotationProcessingConfigBuilder { + private static final Logger LOGGER = LoggerFactory.getLogger(AnnotationProcessing.class); + private final Property group; private final Property incremental; private final Property module; private final ListProperty annotations; private final ListProperty additionalSourceSets; + private final SourceSetConfigurer sourceSetConfigurer; + + public static void showAdditionalSourceSetDeprecationWarning(SourceSet sourceSet) { + LOGGER.warn("Source set '{}' was declared using the additionalSourcesets property. Please use sourceSet(...) instead.", sourceSet.getName()); + } @Inject - public AnnotationProcessing(ObjectFactory objectFactory) { + public AnnotationProcessing(ObjectFactory objectFactory, SourceSetConfigurer sourceSetConfigurer) { this.incremental = objectFactory.property(Boolean.class).convention(true); this.module = objectFactory.property(String.class); this.group = objectFactory.property(String.class); this.annotations = objectFactory.listProperty(String.class); this.additionalSourceSets = objectFactory.listProperty(SourceSet.class); + this.sourceSetConfigurer = sourceSetConfigurer; } /** @@ -59,7 +69,9 @@ public ListProperty getAnnotations() { /** * @return The additional configurations to apply annotation processing to. + * @deprecated Use {@link #sourceSets(SourceSet...)} instead. */ + @Deprecated public ListProperty getAdditionalSourceSets() { return additionalSourceSets; } @@ -67,6 +79,9 @@ public ListProperty getAdditionalSourceSets() { @Override public AnnotationProcessingConfigBuilder sourceSets(SourceSet... sourceSets) { this.additionalSourceSets.addAll(sourceSets); + for (SourceSet sourceSet : sourceSets) { + sourceSetConfigurer.onSourceSet(sourceSet); + } return this; } diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautBasePlugin.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautBasePlugin.java index 45e756ee..ec5b3889 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautBasePlugin.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautBasePlugin.java @@ -23,7 +23,9 @@ public class MicronautBasePlugin implements Plugin { @Override public void apply(Project project) { - project.getExtensions().create("micronaut", MicronautExtension.class); + var registry = new SourceSetConfigurerRegistry(); + project.getExtensions().add("micronautSourceSetConfigurer", registry); + project.getExtensions().create("micronaut", MicronautExtension.class, registry); project.getConfigurations().create(MICRONAUT_BOMS_CONFIGURATION, conf -> { conf.setCanBeResolved(false); conf.setCanBeConsumed(false); diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java index 54e9d8aa..89b748c5 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java @@ -23,7 +23,6 @@ import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.plugins.PluginManager; -import org.gradle.api.provider.ListProperty; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.TaskProvider; @@ -34,6 +33,7 @@ import java.io.File; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -122,42 +122,54 @@ private void configureTesting(Project project, MicronautExtension micronautExten private void configureMicronautBom(Project project, MicronautExtension micronautExtension) { Configuration micronautBoms = project.getConfigurations().getByName(MICRONAUT_BOMS_CONFIGURATION); PluginsHelper.maybeAddMicronautPlaformBom(project, micronautBoms); + var registry = project.getExtensions().getByType(SourceSetConfigurerRegistry.class); + var knownSourceSets = new HashSet(); + registry.register(sourceSet -> { + configureSourceSet(project, sourceSet, micronautBoms); + knownSourceSets.add(sourceSet); + }); project.afterEvaluate(p -> { project.getConfigurations().configureEach(conf -> { if (CONFIGURATIONS_TO_APPLY_BOMS.contains(conf.getName())) { conf.extendsFrom(micronautBoms); } }); - ListProperty additionalSourceSets = + var additionalSourceSets = micronautExtension.getProcessing().getAdditionalSourceSets(); - if (additionalSourceSets.isPresent()) { List configurations = additionalSourceSets.get(); if (!configurations.isEmpty()) { for (SourceSet sourceSet : configurations) { - String annotationProcessorConfigurationName = sourceSet - .getAnnotationProcessorConfigurationName(); - String implementationConfigurationName = sourceSet - .getImplementationConfigurationName(); - List both = Arrays.asList( - implementationConfigurationName, - annotationProcessorConfigurationName - ); - for (String configuration : both) { - Configuration conf = project.getConfigurations().findByName(configuration); - if (conf != null) { - conf.extendsFrom(micronautBoms); - } + if (!knownSourceSets.contains(sourceSet)) { + AnnotationProcessing.showAdditionalSourceSetDeprecationWarning(sourceSet); + configureSourceSet(project, sourceSet, micronautBoms); } - configureAnnotationProcessors(p, - implementationConfigurationName, - annotationProcessorConfigurationName); } } } }); } + private static void configureSourceSet(Project project, SourceSet sourceSet, Configuration micronautBoms) { + String annotationProcessorConfigurationName = sourceSet + .getAnnotationProcessorConfigurationName(); + String implementationConfigurationName = sourceSet + .getImplementationConfigurationName(); + List both = Arrays.asList( + implementationConfigurationName, + annotationProcessorConfigurationName + ); + for (String configuration : both) { + Configuration conf = project.getConfigurations().findByName(configuration); + if (conf != null) { + conf.extendsFrom(micronautBoms); + } + } + configureAnnotationProcessors(project, + implementationConfigurationName, + annotationProcessorConfigurationName); + } + private void configureJava(Project project, TaskContainer tasks) { @@ -250,7 +262,8 @@ private void configureGroovy(Project project, TaskContainer tasks, MicronautExte } } } - ListProperty additionalSourceSets = micronautExtension.getProcessing().getAdditionalSourceSets(); + @SuppressWarnings("deprecation") + var additionalSourceSets = micronautExtension.getProcessing().getAdditionalSourceSets(); if (additionalSourceSets.isPresent()) { List sourceSets = additionalSourceSets.get(); for (SourceSet sourceSet : sourceSets) { diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java index 3190c422..7e4a3c30 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java @@ -35,8 +35,8 @@ public abstract class MicronautExtension implements ExtensionAware { public abstract Property getImportMicronautPlatform(); @Inject - public MicronautExtension(ObjectFactory objectFactory) { - this.processing = objectFactory.newInstance(AnnotationProcessing.class); + public MicronautExtension(ObjectFactory objectFactory, SourceSetConfigurer sourceSetConfigurer) { + this.processing = objectFactory.newInstance(AnnotationProcessing.class, sourceSetConfigurer); this.version = objectFactory.property(String.class); this.enableNativeImage = objectFactory.property(Boolean.class) .convention(true); diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautKotlinSupport.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautKotlinSupport.java index c06b8274..c912d104 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautKotlinSupport.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautKotlinSupport.java @@ -8,7 +8,6 @@ import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.plugins.ExtensionContainer; import org.gradle.api.plugins.PluginManager; -import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskContainer; @@ -19,6 +18,7 @@ import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.function.Consumer; @@ -35,12 +35,12 @@ */ public class MicronautKotlinSupport { private static final String[] KAPT_CONFIGURATIONS = new String[]{ - "kapt", - "kaptTest" + "kapt", + "kaptTest" }; private static final String[] KSP_CONFIGURATIONS = new String[]{ - "ksp", - "kspTest" + "ksp", + "kspTest" }; public static final String KOTLIN_PROCESSORS = "kotlinProcessors"; @@ -110,6 +110,7 @@ private static void configureKapt(Project project) { final ExtensionContainer extensions = project.getExtensions(); extensions.configure(KaptExtension.class, kaptExtension -> { + kaptExtension.setGenerateStubs(false); final MicronautExtension micronautExtension = extensions.getByType(MicronautExtension.class); AnnotationProcessing processingConfig = micronautExtension.getProcessing(); final boolean isIncremental = processingConfig.getIncremental().getOrElse(true); @@ -141,7 +142,6 @@ private static void configureKapt(Project project) { private static void configureKotlinCompilerPlugin(Project project, String[] compilerConfigurations, String compilerType, List annotationProcessorModules) { // add inject-java to kapt scopes - DependencyHandler dependencies = project.getDependencies(); PluginsHelper.registerAnnotationProcessors(project, annotationProcessorModules, compilerConfigurations); addGraalVmDependencies(compilerConfigurations, project); @@ -149,57 +149,80 @@ private static void configureKotlinCompilerPlugin(Project project, String[] comp for (String compilerConfiguration : compilerConfigurations) { project.getConfigurations().getByName(compilerConfiguration).extendsFrom(kotlinProcessors); } - + PluginsHelper.applyAdditionalProcessors( + project, + compilerConfigurations + ); + var registry = project. + getExtensions() + .getByType(SourceSetConfigurerRegistry.class); + var dependencyHandler = project.getDependencies(); + var platform = PluginsHelper.findMicronautVersion(project).map(micronautVersion -> resolveMicronautPlatform(dependencyHandler, micronautVersion)); + var knownSourceSets = new HashSet(); + registry.register(sourceSet -> { + configureAdditionalSourceSet(compilerType, project, dependencyHandler, platform, sourceSet); + knownSourceSets.add(sourceSet); + }); + for (String compileConfiguration : compilerConfigurations) { + dependencyHandler.addProvider( + compileConfiguration, + platform + ); + } project.afterEvaluate(p -> { PluginsHelper.applyAdditionalProcessors( - p, - compilerConfigurations + p, + compilerConfigurations ); - final MicronautExtension micronautExtension = p - .getExtensions() - .getByType(MicronautExtension.class); - ListProperty additionalSourceSets = - micronautExtension.getProcessing().getAdditionalSourceSets(); - final DependencyHandler dependencyHandler = p.getDependencies(); - Provider platform = PluginsHelper.findMicronautVersion(p).map(micronautVersion -> resolveMicronautPlatform(dependencyHandler, micronautVersion)); - if (additionalSourceSets.isPresent()) { - List configurations = additionalSourceSets.get(); - if (!configurations.isEmpty()) { - for (SourceSet sourceSet : configurations) { - configureAdditionalSourceSet(compilerType, dependencies, p, dependencyHandler, platform, sourceSet); - } - } - } + configureExtraSourceSetsUsingDeprecatedBehavior(compilerType, p, knownSourceSets, dependencyHandler, platform); + }); + } - for (String compileConfiguration : compilerConfigurations) { - dependencyHandler.addProvider( - compileConfiguration, - platform - ); + private static void configureExtraSourceSetsUsingDeprecatedBehavior(String compilerType, Project p, HashSet knownSourceSets, DependencyHandler dependencyHandler, Provider platform) { + var micronautExtension = p + .getExtensions() + .getByType(MicronautExtension.class); + @SuppressWarnings("deprecation") + var additionalSourceSets = + micronautExtension.getProcessing() + .getAdditionalSourceSets(); + if (additionalSourceSets.isPresent()) { + List configurations = additionalSourceSets.get(); + if (!configurations.isEmpty()) { + for (SourceSet sourceSet : configurations) { + if (!knownSourceSets.contains(sourceSet)) { + AnnotationProcessing.showAdditionalSourceSetDeprecationWarning(sourceSet); + configureAdditionalSourceSet(compilerType, p, dependencyHandler, platform, sourceSet); + } + } } - }); + } } - private static void configureAdditionalSourceSet(String compilerType, DependencyHandler dependencies, Project p, DependencyHandler dependencyHandler, Provider platform, SourceSet sourceSet) { + private static void configureAdditionalSourceSet(String compilerType, + Project p, + DependencyHandler dependencyHandler, + Provider platform, + SourceSet sourceSet) { String annotationProcessorConfigurationName = compilerType + Strings.capitalize(sourceSet.getName()); String implementationConfigurationName = sourceSet - .getImplementationConfigurationName(); + .getImplementationConfigurationName(); List both = Arrays.asList( - implementationConfigurationName, - annotationProcessorConfigurationName + implementationConfigurationName, + annotationProcessorConfigurationName ); for (String configuration : both) { dependencyHandler.addProvider( - configuration, - platform + configuration, + platform ); } configureAnnotationProcessors(p, - implementationConfigurationName, - annotationProcessorConfigurationName); + implementationConfigurationName, + annotationProcessorConfigurationName); p.getPluginManager().withPlugin("io.micronaut.graalvm", unused -> - new AutomaticDependency(annotationProcessorConfigurationName, + new AutomaticDependency(annotationProcessorConfigurationName, "io.micronaut:micronaut-graal", Optional.of(CORE_VERSION_PROPERTY)).applyTo(p) ); @@ -209,8 +232,8 @@ private static void addGraalVmDependencies(String[] compilerConfigurations, Proj project.getPluginManager().withPlugin("io.micronaut.graalvm", unused -> { for (String configuration : compilerConfigurations) { new AutomaticDependency(configuration, - "io.micronaut:micronaut-graal", - Optional.of(CORE_VERSION_PROPERTY)).applyTo(project); + "io.micronaut:micronaut-graal", + Optional.of(CORE_VERSION_PROPERTY)).applyTo(project); } }); } diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurer.java b/minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurer.java new file mode 100644 index 00000000..9f942102 --- /dev/null +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurer.java @@ -0,0 +1,22 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.gradle; + +import org.gradle.api.tasks.SourceSet; + +public interface SourceSetConfigurer { + void onSourceSet(SourceSet sourceSet); +} diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurerRegistry.java b/minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurerRegistry.java new file mode 100644 index 00000000..db5d7391 --- /dev/null +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/SourceSetConfigurerRegistry.java @@ -0,0 +1,37 @@ +/* + * Copyright 2003-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.micronaut.gradle; + +import org.gradle.api.tasks.SourceSet; + +import java.util.ArrayList; +import java.util.List; + +public class SourceSetConfigurerRegistry implements SourceSetConfigurer { + private final List configurers = new ArrayList<>(); + + public void register(SourceSetConfigurer configurer) { + configurers.add(configurer); + } + + + @Override + public void onSourceSet(SourceSet sourceSet) { + for (SourceSetConfigurer configurer : configurers) { + configurer.onSourceSet(sourceSet); + } + } +} diff --git a/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy b/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy new file mode 100644 index 00000000..616fb1d0 --- /dev/null +++ b/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy @@ -0,0 +1,82 @@ +package io.micronaut.gradle + +import org.gradle.testkit.runner.TaskOutcome + +class MicronautDeprecationsPluginSpec extends AbstractGradleBuildSpec { + + def "shows deprecation warning when using additionalSourceSets"() { + given: + settingsFile << "rootProject.name = 'hello-world'" + buildFile << """ + plugins { + id "io.micronaut.minimal.application" + } + + sourceSets { + custom { + java.srcDir('src/custom/java') + } + } + + micronaut { + version "$micronautVersion" + runtime "netty" + testRuntime "junit5" + processing { + additionalSourceSets.add(sourceSets.custom) + } + } + + $repositoriesBlock + mainClassName="example.Application" + + $withSerde + """ + when: + def result = build('assemble') + + def task = result.task(":assemble") + + then: + result.output.contains("Source set 'custom' was declared using the additionalSourcesets property. Please use sourceSet(...) instead.\n") + task.outcome == TaskOutcome.SUCCESS + } + + def "doesn't show deprecation warning when using sourceSet(...)"() { + given: + settingsFile << "rootProject.name = 'hello-world'" + buildFile << """ + plugins { + id "io.micronaut.minimal.application" + } + + sourceSets { + custom { + java.srcDir('src/custom/java') + } + } + + micronaut { + version "$micronautVersion" + runtime "netty" + testRuntime "junit5" + processing { + sourceSets(sourceSets.custom) + } + } + + $repositoriesBlock + mainClassName="example.Application" + + $withSerde + """ + when: + def result = build('assemble') + + def task = result.task(":assemble") + + then: + !result.output.contains("Source set 'custom' was declared using the additionalSourcesets property. Please use sourceSet(...) instead.\n") + task.outcome == TaskOutcome.SUCCESS + } +}