mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-02 11:24:04 +08:00
Support annotationProcessor scope
Fixes gh-653
This commit is contained in:
@@ -404,6 +404,8 @@ public class ProjectGenerator {
|
|||||||
filterDependencies(dependencies, Dependency.SCOPE_RUNTIME));
|
filterDependencies(dependencies, Dependency.SCOPE_RUNTIME));
|
||||||
model.put("compileOnlyDependencies",
|
model.put("compileOnlyDependencies",
|
||||||
filterDependencies(dependencies, Dependency.SCOPE_COMPILE_ONLY));
|
filterDependencies(dependencies, Dependency.SCOPE_COMPILE_ONLY));
|
||||||
|
model.put("annotationProcessorDependencies",
|
||||||
|
filterDependencies(dependencies, Dependency.SCOPE_ANNOTATION_PROCESSOR));
|
||||||
model.put("providedDependencies",
|
model.put("providedDependencies",
|
||||||
filterDependencies(dependencies, Dependency.SCOPE_PROVIDED));
|
filterDependencies(dependencies, Dependency.SCOPE_PROVIDED));
|
||||||
model.put("testDependencies",
|
model.put("testDependencies",
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
*/
|
*/
|
||||||
public static final String SCOPE_COMPILE_ONLY = "compileOnly";
|
public static final String SCOPE_COMPILE_ONLY = "compileOnly";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation Processor Scope.
|
||||||
|
*/
|
||||||
|
public static final String SCOPE_ANNOTATION_PROCESSOR = "annotationProcessor";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runtime Scope.
|
* Runtime Scope.
|
||||||
*/
|
*/
|
||||||
@@ -68,9 +73,9 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
/**
|
/**
|
||||||
* All scope types.
|
* All scope types.
|
||||||
*/
|
*/
|
||||||
public static final List<String> SCOPE_ALL = Collections
|
public static final List<String> SCOPE_ALL = Collections.unmodifiableList(
|
||||||
.unmodifiableList(Arrays.asList(SCOPE_COMPILE, SCOPE_RUNTIME,
|
Arrays.asList(SCOPE_COMPILE, SCOPE_RUNTIME, SCOPE_COMPILE_ONLY,
|
||||||
SCOPE_COMPILE_ONLY, SCOPE_PROVIDED, SCOPE_TEST));
|
SCOPE_ANNOTATION_PROCESSOR, SCOPE_PROVIDED, SCOPE_TEST));
|
||||||
|
|
||||||
private List<String> aliases = new ArrayList<>();
|
private List<String> aliases = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ dependencies {
|
|||||||
{{#compileOnlyDependencies}}
|
{{#compileOnlyDependencies}}
|
||||||
compileOnly('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
|
compileOnly('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
|
||||||
{{/compileOnlyDependencies}}
|
{{/compileOnlyDependencies}}
|
||||||
|
{{#annotationProcessorDependencies}}
|
||||||
|
annotationProcessor('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
|
||||||
|
{{/annotationProcessorDependencies}}
|
||||||
{{#providedDependencies}}
|
{{#providedDependencies}}
|
||||||
providedRuntime('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
|
providedRuntime('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
|
||||||
{{/providedDependencies}}
|
{{/providedDependencies}}
|
||||||
|
|||||||
@@ -89,6 +89,19 @@
|
|||||||
{{/type}}
|
{{/type}}
|
||||||
</dependency>
|
</dependency>
|
||||||
{{/compileOnlyDependencies}}
|
{{/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}}
|
{{#providedDependencies}}
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>{{groupId}}</groupId>
|
<groupId>{{groupId}}</groupId>
|
||||||
|
|||||||
@@ -143,6 +143,24 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
|||||||
+ this.build + "/compile-only-dependency-" + this.assertFileName));
|
+ 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
|
@Test
|
||||||
public void bomWithOrdering() {
|
public void bomWithOrdering() {
|
||||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||||
|
|||||||
@@ -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')
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
Reference in New Issue
Block a user