mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Add workaround for annotationProcessor scope detection in IJ
Closes gh-848
This commit is contained in:
@@ -39,6 +39,13 @@ public class GradleConfigurationBuildCustomizer implements BuildCustomizer<Gradl
|
||||
if (providedRuntimeUsed && !war) {
|
||||
build.addConfiguration("providedRuntime");
|
||||
}
|
||||
boolean annotationProcessorUsed = build.dependencies().items()
|
||||
.anyMatch((dependency) -> dependency
|
||||
.getScope() == DependencyScope.ANNOTATION_PROCESSOR);
|
||||
if (annotationProcessorUsed) {
|
||||
build.customizeConfiguration("compileOnly",
|
||||
(configuration) -> configuration.extendsFrom("annotationProcessor"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -65,6 +65,30 @@ class GradleConfigurationBuildCustomizerTests {
|
||||
assertThat(build.getConfigurationCustomizations()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void compileOnlyConfigurationIsAddedWithAnnotationProcessorDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("lib", "com.example", "lib", DependencyScope.COMPILE);
|
||||
build.dependencies().add("ap", "com.example", "model-generator",
|
||||
DependencyScope.ANNOTATION_PROCESSOR);
|
||||
customize(build);
|
||||
assertThat(build.getConfigurationCustomizations())
|
||||
.containsOnlyKeys("compileOnly");
|
||||
ConfigurationCustomization compileOnly = build.getConfigurationCustomizations()
|
||||
.get("compileOnly");
|
||||
assertThat(compileOnly.getExtendsFrom()).containsOnly("annotationProcessor");
|
||||
}
|
||||
|
||||
@Test
|
||||
void compileOnlyConfigurationIsNotAddedWithNonMatchingDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("lib", "com.example", "lib", DependencyScope.COMPILE);
|
||||
build.dependencies().add("another", "com.example", "another",
|
||||
DependencyScope.RUNTIME);
|
||||
customize(build);
|
||||
assertThat(build.getConfigurationCustomizations()).isEmpty();
|
||||
}
|
||||
|
||||
private void customize(GradleBuild build) {
|
||||
new GradleConfigurationBuildCustomizer().customize(build);
|
||||
}
|
||||
|
@@ -9,6 +9,12 @@ group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom annotationProcessor
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
Reference in New Issue
Block a user