Support annotationProcessor scope

Fixes gh-653
This commit is contained in:
Madhura Bhave 2018-07-03 14:32:15 -07:00
parent 3a3f65e5ef
commit ec87ca3ace
7 changed files with 136 additions and 3 deletions

View File

@ -404,6 +404,8 @@ public class ProjectGenerator {
filterDependencies(dependencies, Dependency.SCOPE_RUNTIME));
model.put("compileOnlyDependencies",
filterDependencies(dependencies, Dependency.SCOPE_COMPILE_ONLY));
model.put("annotationProcessorDependencies",
filterDependencies(dependencies, Dependency.SCOPE_ANNOTATION_PROCESSOR));
model.put("providedDependencies",
filterDependencies(dependencies, Dependency.SCOPE_PROVIDED));
model.put("testDependencies",

View File

@ -50,6 +50,11 @@ public class Dependency extends MetadataElement implements Describable {
*/
public static final String SCOPE_COMPILE_ONLY = "compileOnly";
/**
* Annotation Processor Scope.
*/
public static final String SCOPE_ANNOTATION_PROCESSOR = "annotationProcessor";
/**
* Runtime Scope.
*/
@ -68,9 +73,9 @@ public class Dependency extends MetadataElement implements Describable {
/**
* All scope types.
*/
public static final List<String> SCOPE_ALL = Collections
.unmodifiableList(Arrays.asList(SCOPE_COMPILE, SCOPE_RUNTIME,
SCOPE_COMPILE_ONLY, SCOPE_PROVIDED, SCOPE_TEST));
public static final List<String> SCOPE_ALL = Collections.unmodifiableList(
Arrays.asList(SCOPE_COMPILE, SCOPE_RUNTIME, SCOPE_COMPILE_ONLY,
SCOPE_ANNOTATION_PROCESSOR, SCOPE_PROVIDED, SCOPE_TEST));
private List<String> aliases = new ArrayList<>();

View File

@ -98,6 +98,9 @@ dependencies {
{{#compileOnlyDependencies}}
compileOnly('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
{{/compileOnlyDependencies}}
{{#annotationProcessorDependencies}}
annotationProcessor('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
{{/annotationProcessorDependencies}}
{{#providedDependencies}}
providedRuntime('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
{{/providedDependencies}}

View File

@ -89,6 +89,19 @@
{{/type}}
</dependency>
{{/compileOnlyDependencies}}
{{#annotationProcessorDependencies}}
<dependency>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
{{#version}}
<version>{{version}}</version>
{{/version}}
<optional>true</optional>
{{#type}}
<type>{{type}}</type>
{{/type}}
</dependency>
{{/annotationProcessorDependencies}}
{{#providedDependencies}}
<dependency>
<groupId>{{groupId}}</groupId>

View File

@ -143,6 +143,24 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
+ this.build + "/compile-only-dependency-" + this.assertFileName));
}
@Test
public void annotationProcessorDependency() {
Dependency annotationProcessor = Dependency.withId("configuration-processor",
"org.springframework.boot", "spring-boot-configuration-processor");
annotationProcessor.setScope(Dependency.SCOPE_ANNOTATION_PROCESSOR);
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("core", "web", "data-jpa")
.addDependencyGroup("configuration-processor", annotationProcessor)
.build();
applyMetadata(metadata);
ProjectRequest request = createProjectRequest("configuration-processor", "web",
"data-jpa");
ProjectAssert project = generateProject(request);
project.sourceCodeAssert(this.fileName)
.equalsTo(new ClassPathResource("project/" + this.build
+ "/annotation-processor-dependency-" + this.assertFileName));
}
@Test
public void bomWithOrdering() {
Dependency foo = Dependency.withId("foo", "org.acme", "foo");

View File

@ -0,0 +1,33 @@
buildscript {
ext {
springBootVersion = '1.2.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
annotationProcessor('org.springframework.boot:spring-boot-configuration-processor')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>