mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Polish "Add dependency classifier support"
See gh-1049
This commit is contained in:
@@ -90,6 +90,7 @@ with that id is assumed.
|
|||||||
* A `version` if Spring Boot does not already provide a dependency management for
|
* A `version` if Spring Boot does not already provide a dependency management for
|
||||||
that dependency.
|
that dependency.
|
||||||
* A `scope` (can be `compile`, `runtime`, `provided` or `test`).
|
* A `scope` (can be `compile`, `runtime`, `provided` or `test`).
|
||||||
|
* A `classifier` (if the dependency to use is classified, such as `test-jar`).
|
||||||
* The reference to a `bom` or a `repository` that must be added to the project once
|
* The reference to a `bom` or a `repository` that must be added to the project once
|
||||||
that dependency is added.
|
that dependency is added.
|
||||||
* A `compatibilityRange` used to determine the platform versions that are compatible
|
* A `compatibilityRange` used to determine the platform versions that are compatible
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,10 +41,10 @@ public class Dependency {
|
|||||||
|
|
||||||
private final DependencyScope scope;
|
private final DependencyScope scope;
|
||||||
|
|
||||||
private final String type;
|
|
||||||
|
|
||||||
private final String classifier;
|
private final String classifier;
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
private final Set<Exclusion> exclusions;
|
private final Set<Exclusion> exclusions;
|
||||||
|
|
||||||
protected Dependency(Builder<?> builder) {
|
protected Dependency(Builder<?> builder) {
|
||||||
@@ -110,6 +110,14 @@ public class Dependency {
|
|||||||
return this.scope;
|
return this.scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The classifier of this dependency. Can be {@code null}
|
||||||
|
* @return the classifier or {@code null}
|
||||||
|
*/
|
||||||
|
public String getClassifier() {
|
||||||
|
return this.classifier;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of the dependency. Can be {@code null} to indicate that the default type
|
* The type of the dependency. Can be {@code null} to indicate that the default type
|
||||||
* should be used (i.e. {@code jar}).
|
* should be used (i.e. {@code jar}).
|
||||||
@@ -119,14 +127,6 @@ public class Dependency {
|
|||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The classifier of this dependency. Can be {@code null}
|
|
||||||
* @return the classifier or {@code null}
|
|
||||||
*/
|
|
||||||
public String getClassifier() {
|
|
||||||
return this.classifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Exclusion exclusions} to apply.
|
* The {@link Exclusion exclusions} to apply.
|
||||||
* @return the exclusions to apply
|
* @return the exclusions to apply
|
||||||
@@ -151,10 +151,10 @@ public class Dependency {
|
|||||||
|
|
||||||
private DependencyScope scope;
|
private DependencyScope scope;
|
||||||
|
|
||||||
private String classifier;
|
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
private String classifier;
|
||||||
|
|
||||||
private Set<Exclusion> exclusions = new LinkedHashSet<>();
|
private Set<Exclusion> exclusions = new LinkedHashSet<>();
|
||||||
|
|
||||||
protected Builder(String groupId, String artifactId) {
|
protected Builder(String groupId, String artifactId) {
|
||||||
@@ -182,13 +182,13 @@ public class Dependency {
|
|||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public B type(String type) {
|
public B classifier(String classifier) {
|
||||||
this.type = type;
|
this.classifier = classifier;
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public B classifier(String classifier) {
|
public B type(String type) {
|
||||||
this.classifier = classifier;
|
this.type = type;
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,8 +208,8 @@ public class Dependency {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected B initialize(Dependency dependency) {
|
protected B initialize(Dependency dependency) {
|
||||||
version(dependency.getVersion()).scope(dependency.getScope()).type(dependency.getType())
|
version(dependency.getVersion()).scope(dependency.getScope()).classifier(dependency.getClassifier())
|
||||||
.exclusions(dependency.getExclusions());
|
.type(dependency.getType()).exclusions(dependency.getExclusions());
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -134,8 +134,8 @@ public class GroovyDslGradleBuildWriter extends GradleBuildWriter {
|
|||||||
protected void writeDependency(IndentingWriter writer, Dependency dependency) {
|
protected void writeDependency(IndentingWriter writer, Dependency dependency) {
|
||||||
String quoteStyle = determineQuoteStyle(dependency.getVersion());
|
String quoteStyle = determineQuoteStyle(dependency.getVersion());
|
||||||
String version = determineVersion(dependency.getVersion());
|
String version = determineVersion(dependency.getVersion());
|
||||||
String type = dependency.getType();
|
|
||||||
String classifier = dependency.getClassifier();
|
String classifier = dependency.getClassifier();
|
||||||
|
String type = dependency.getType();
|
||||||
boolean hasExclusions = !dependency.getExclusions().isEmpty();
|
boolean hasExclusions = !dependency.getExclusions().isEmpty();
|
||||||
writer.print(configurationForDependency(dependency));
|
writer.print(configurationForDependency(dependency));
|
||||||
writer.print((hasExclusions) ? "(" : " ");
|
writer.print((hasExclusions) ? "(" : " ");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -149,8 +149,8 @@ public class KotlinDslGradleBuildWriter extends GradleBuildWriter {
|
|||||||
@Override
|
@Override
|
||||||
protected void writeDependency(IndentingWriter writer, Dependency dependency) {
|
protected void writeDependency(IndentingWriter writer, Dependency dependency) {
|
||||||
String version = determineVersion(dependency.getVersion());
|
String version = determineVersion(dependency.getVersion());
|
||||||
String type = dependency.getType();
|
|
||||||
String classifier = dependency.getClassifier();
|
String classifier = dependency.getClassifier();
|
||||||
|
String type = dependency.getType();
|
||||||
writer.print(configurationForDependency(dependency) + "(\"" + dependency.getGroupId() + ":"
|
writer.print(configurationForDependency(dependency) + "(\"" + dependency.getGroupId() + ":"
|
||||||
+ dependency.getArtifactId() + ((version != null) ? ":" + version : "")
|
+ dependency.getArtifactId() + ((version != null) ? ":" + version : "")
|
||||||
+ ((classifier != null) ? ":" + classifier : "") + ((type != null) ? "@" + type : "") + "\")");
|
+ ((classifier != null) ? ":" + classifier : "") + ((type != null) ? "@" + type : "") + "\")");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ public class MavenDependency extends Dependency {
|
|||||||
* @return a new builder initialized with the same state as the {@code dependency}
|
* @return a new builder initialized with the same state as the {@code dependency}
|
||||||
*/
|
*/
|
||||||
public static Builder from(Dependency dependency) {
|
public static Builder from(Dependency dependency) {
|
||||||
return new Builder(dependency.getGroupId(), dependency.getArtifactId()).initialize(dependency)
|
return new Builder(dependency.getGroupId(), dependency.getArtifactId()).initialize(dependency);
|
||||||
.classifier(dependency.getClassifier());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -36,6 +36,7 @@ class DependencyTests {
|
|||||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||||
assertThat(dependency.getScope()).isNull();
|
assertThat(dependency.getScope()).isNull();
|
||||||
assertThat(dependency.getVersion()).isNull();
|
assertThat(dependency.getVersion()).isNull();
|
||||||
|
assertThat(dependency.getClassifier()).isNull();
|
||||||
assertThat(dependency.getType()).isNull();
|
assertThat(dependency.getType()).isNull();
|
||||||
assertThat(dependency.getExclusions()).isEmpty();
|
assertThat(dependency.getExclusions()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -48,6 +49,19 @@ class DependencyTests {
|
|||||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||||
assertThat(dependency.getVersion().getValue()).isEqualTo("1.0.0");
|
assertThat(dependency.getVersion().getValue()).isEqualTo("1.0.0");
|
||||||
|
assertThat(dependency.getClassifier()).isNull();
|
||||||
|
assertThat(dependency.getType()).isNull();
|
||||||
|
assertThat(dependency.getExclusions()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dependencyWithClassifier() {
|
||||||
|
Dependency dependency = Dependency.withCoordinates("com.example", "acme").classifier("test").build();
|
||||||
|
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||||
|
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||||
|
assertThat(dependency.getScope()).isNull();
|
||||||
|
assertThat(dependency.getVersion()).isNull();
|
||||||
|
assertThat(dependency.getClassifier()).isEqualTo("test");
|
||||||
assertThat(dependency.getType()).isNull();
|
assertThat(dependency.getType()).isNull();
|
||||||
assertThat(dependency.getExclusions()).isEmpty();
|
assertThat(dependency.getExclusions()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -59,6 +73,7 @@ class DependencyTests {
|
|||||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||||
assertThat(dependency.getScope()).isNull();
|
assertThat(dependency.getScope()).isNull();
|
||||||
assertThat(dependency.getVersion()).isNull();
|
assertThat(dependency.getVersion()).isNull();
|
||||||
|
assertThat(dependency.getClassifier()).isNull();
|
||||||
assertThat(dependency.getType()).isEqualTo("test-zip");
|
assertThat(dependency.getType()).isEqualTo("test-zip");
|
||||||
assertThat(dependency.getExclusions()).isEmpty();
|
assertThat(dependency.getExclusions()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -71,6 +86,7 @@ class DependencyTests {
|
|||||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||||
assertThat(dependency.getScope()).isNull();
|
assertThat(dependency.getScope()).isNull();
|
||||||
assertThat(dependency.getVersion()).isNull();
|
assertThat(dependency.getVersion()).isNull();
|
||||||
|
assertThat(dependency.getClassifier()).isNull();
|
||||||
assertThat(dependency.getType()).isNull();
|
assertThat(dependency.getType()).isNull();
|
||||||
assertThat(dependency.getExclusions()).containsExactly(new Exclusion("com.example", "exclude1"),
|
assertThat(dependency.getExclusions()).containsExactly(new Exclusion("com.example", "exclude1"),
|
||||||
new Exclusion("com.example", "exclude2"));
|
new Exclusion("com.example", "exclude2"));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -305,16 +305,6 @@ class GroovyDslGradleBuildWriterTests {
|
|||||||
" implementation 'org.springframework.boot:spring-boot-starter'", "}");
|
" implementation 'org.springframework.boot:spring-boot-starter'", "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void gradleBuildWithClassifierDependency() {
|
|
||||||
GradleBuild build = new GradleBuild();
|
|
||||||
build.dependencies().add("root",
|
|
||||||
Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter").classifier("classifier"));
|
|
||||||
List<String> lines = generateBuild(build);
|
|
||||||
assertThat(lines).containsSequence("dependencies {",
|
|
||||||
" implementation 'org.springframework.boot:spring-boot-starter:classifier'", "}");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
@@ -373,6 +363,14 @@ class GroovyDslGradleBuildWriterTests {
|
|||||||
" testRuntimeOnly 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'", "}");
|
" testRuntimeOnly 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'", "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gradleBuildWithClassifierDependency() {
|
||||||
|
GradleBuild build = new GradleBuild();
|
||||||
|
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme").classifier("test-jar"));
|
||||||
|
List<String> lines = generateBuild(build);
|
||||||
|
assertThat(lines).containsSequence("dependencies {", " implementation 'com.example:acme:test-jar'", "}");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void gradleBuildWithExclusions() {
|
void gradleBuildWithExclusions() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
@@ -410,11 +408,11 @@ class GroovyDslGradleBuildWriterTests {
|
|||||||
@Test
|
@Test
|
||||||
void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
|
void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
|
||||||
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("classifier"));
|
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("test-jar"));
|
||||||
List<String> lines = generateBuild(build);
|
List<String> lines = generateBuild(build);
|
||||||
assertThat(lines).containsSequence("dependencies {",
|
assertThat(lines).containsSequence("dependencies {", " implementation 'com.example:acme:test-jar@tar.gz'",
|
||||||
" implementation 'org.springframework.boot:spring-boot-starter:classifier@tar.gz'", "}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -313,16 +313,6 @@ class KotlinDslGradleBuildWriterTests {
|
|||||||
" implementation(\"org.springframework.boot:spring-boot-starter\")", "}");
|
" implementation(\"org.springframework.boot:spring-boot-starter\")", "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void gradleBuildWithClassifierDependency() {
|
|
||||||
GradleBuild build = new GradleBuild();
|
|
||||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
|
||||||
.scope(DependencyScope.COMPILE).classifier("classifier"));
|
|
||||||
List<String> lines = generateBuild(build);
|
|
||||||
assertThat(lines).containsSequence("dependencies {",
|
|
||||||
" implementation(\"org.springframework.boot:spring-boot-starter:classifier\")", "}");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
@@ -381,6 +371,15 @@ class KotlinDslGradleBuildWriterTests {
|
|||||||
" testRuntimeOnly(\"de.flapdoodle.embed:de.flapdoodle.embed.mongo\")", "}");
|
" testRuntimeOnly(\"de.flapdoodle.embed:de.flapdoodle.embed.mongo\")", "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void gradleBuildWithClassifierDependency() {
|
||||||
|
GradleBuild build = new GradleBuild();
|
||||||
|
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
|
||||||
|
.scope(DependencyScope.COMPILE).classifier("test-jar"));
|
||||||
|
List<String> lines = generateBuild(build);
|
||||||
|
assertThat(lines).containsSequence("dependencies {", " implementation(\"com.example:acme:test-jar\")", "}");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void gradleBuildWithExclusions() {
|
void gradleBuildWithExclusions() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
@@ -418,11 +417,11 @@ class KotlinDslGradleBuildWriterTests {
|
|||||||
@Test
|
@Test
|
||||||
void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
|
void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
|
||||||
GradleBuild build = new GradleBuild();
|
GradleBuild build = new GradleBuild();
|
||||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
|
||||||
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("classifier"));
|
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("test-jar"));
|
||||||
List<String> lines = generateBuild(build);
|
List<String> lines = generateBuild(build);
|
||||||
assertThat(lines).containsSequence("dependencies {",
|
assertThat(lines).containsSequence("dependencies {", " implementation(\"com.example:acme:test-jar@tar.gz\")",
|
||||||
" implementation(\"org.springframework.boot:spring-boot-starter:classifier@tar.gz\")", "}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -223,20 +223,6 @@ class MavenBuildWriterTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void pomWithClassifierDependency() {
|
|
||||||
MavenBuild build = new MavenBuild();
|
|
||||||
build.settings().coordinates("com.example.demo", "demo");
|
|
||||||
build.dependencies().add("foo-bar", Dependency
|
|
||||||
.withCoordinates("org.springframework.boot", "spring-boot-foo-bar").classifier("myClassifier"));
|
|
||||||
generatePom(build, (pom) -> {
|
|
||||||
NodeAssert dependency = pom.nodeAtPath("/project/dependencies/dependency");
|
|
||||||
assertThat(dependency).textAtPath("groupId").isEqualTo("org.springframework.boot");
|
|
||||||
assertThat(dependency).textAtPath("artifactId").isEqualTo("spring-boot-foo-bar");
|
|
||||||
assertThat(dependency).textAtPath("classifier").isEqualTo("myClassifier");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithCompileOnlyDependency() {
|
void pomWithCompileOnlyDependency() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
@@ -346,6 +332,19 @@ class MavenBuildWriterTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pomWithClassifierDependency() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.settings().coordinates("com.example.demo", "demo");
|
||||||
|
build.dependencies().add("foo-bar", Dependency.withCoordinates("com.example", "acme").classifier("test-jar"));
|
||||||
|
generatePom(build, (pom) -> {
|
||||||
|
NodeAssert dependency = pom.nodeAtPath("/project/dependencies/dependency");
|
||||||
|
assertThat(dependency).textAtPath("groupId").isEqualTo("com.example");
|
||||||
|
assertThat(dependency).textAtPath("artifactId").isEqualTo("acme");
|
||||||
|
assertThat(dependency).textAtPath("classifier").isEqualTo("test-jar");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithExclusions() {
|
void pomWithExclusions() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -33,24 +33,24 @@ class MavenDependencyTests {
|
|||||||
@Test
|
@Test
|
||||||
void initializeFromStandardDependency() {
|
void initializeFromStandardDependency() {
|
||||||
Dependency original = Dependency.withCoordinates("com.example", "test")
|
Dependency original = Dependency.withCoordinates("com.example", "test")
|
||||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).type("zip")
|
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).classifier("test-jar")
|
||||||
.classifier("classifier").build();
|
.type("zip").build();
|
||||||
MavenDependency dependency = MavenDependency.from(original).build();
|
MavenDependency dependency = MavenDependency.from(original).build();
|
||||||
assertThat(original).isNotSameAs(dependency);
|
assertThat(original).isNotSameAs(dependency);
|
||||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||||
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
||||||
assertThat(dependency.getVersion()).isEqualTo(VersionReference.ofValue("1.0.0"));
|
assertThat(dependency.getVersion()).isEqualTo(VersionReference.ofValue("1.0.0"));
|
||||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||||
|
assertThat(dependency.getClassifier()).isEqualTo("test-jar");
|
||||||
assertThat(dependency.getType()).isEqualTo("zip");
|
assertThat(dependency.getType()).isEqualTo("zip");
|
||||||
assertThat(dependency.getClassifier()).isEqualTo("classifier");
|
|
||||||
assertThat(dependency.isOptional()).isFalse();
|
assertThat(dependency.isOptional()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void initializeFromMavenDependency() {
|
void initializeFromMavenDependency() {
|
||||||
Dependency original = MavenDependency.withCoordinates("com.example", "test")
|
Dependency original = MavenDependency.withCoordinates("com.example", "test")
|
||||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).type("zip").optional(true)
|
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).classifier("test-jar")
|
||||||
.classifier("classifier").build();
|
.type("zip").optional(true).build();
|
||||||
MavenDependency dependency = MavenDependency.from(original).build();
|
MavenDependency dependency = MavenDependency.from(original).build();
|
||||||
assertThat(original).isNotSameAs(dependency);
|
assertThat(original).isNotSameAs(dependency);
|
||||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||||
@@ -58,18 +58,8 @@ class MavenDependencyTests {
|
|||||||
assertThat(dependency.getVersion()).isEqualTo(VersionReference.ofValue("1.0.0"));
|
assertThat(dependency.getVersion()).isEqualTo(VersionReference.ofValue("1.0.0"));
|
||||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||||
assertThat(dependency.getType()).isEqualTo("zip");
|
assertThat(dependency.getType()).isEqualTo("zip");
|
||||||
assertThat(dependency.getClassifier()).isEqualTo("classifier");
|
assertThat(dependency.getClassifier()).isEqualTo("test-jar");
|
||||||
assertThat(dependency.isOptional()).isTrue();
|
assertThat(dependency.isOptional()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void cloneUsingFromMethodOfMavenDependency() {
|
|
||||||
Dependency original = Dependency.withCoordinates("com.example", "test").classifier("classifier").build();
|
|
||||||
Dependency dependency = MavenDependency.from(original).build();
|
|
||||||
assertThat(original).isNotSameAs(dependency);
|
|
||||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
|
||||||
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
|
||||||
assertThat(dependency.getClassifier()).isEqualTo("classifier");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -87,10 +87,10 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
|
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
private String classifier;
|
private String classifier;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
private List<Mapping> mappings = new ArrayList<>();
|
private List<Mapping> mappings = new ArrayList<>();
|
||||||
|
|
||||||
private String scope = SCOPE_COMPILE;
|
private String scope = SCOPE_COMPILE;
|
||||||
@@ -132,6 +132,7 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
this.groupId = dependency.groupId;
|
this.groupId = dependency.groupId;
|
||||||
this.artifactId = dependency.artifactId;
|
this.artifactId = dependency.artifactId;
|
||||||
this.version = dependency.version;
|
this.version = dependency.version;
|
||||||
|
this.classifier = dependency.classifier;
|
||||||
this.type = dependency.type;
|
this.type = dependency.type;
|
||||||
this.mappings.addAll(dependency.mappings);
|
this.mappings.addAll(dependency.mappings);
|
||||||
this.scope = dependency.scope;
|
this.scope = dependency.scope;
|
||||||
@@ -145,7 +146,6 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
this.starter = dependency.starter;
|
this.starter = dependency.starter;
|
||||||
this.keywords.addAll(dependency.keywords);
|
this.keywords.addAll(dependency.keywords);
|
||||||
this.links.addAll(dependency.links);
|
this.links.addAll(dependency.links);
|
||||||
this.classifier = dependency.classifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScope(String scope) {
|
public void setScope(String scope) {
|
||||||
@@ -328,6 +328,11 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the classifier, can be {@code null} to indicate that no classifier is
|
||||||
|
* available.
|
||||||
|
* @return the classifier or {@code null}
|
||||||
|
*/
|
||||||
public String getClassifier() {
|
public String getClassifier() {
|
||||||
return this.classifier;
|
return this.classifier;
|
||||||
}
|
}
|
||||||
@@ -469,18 +474,12 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Dependency withId(String id, String groupId, String artifactId, String version, String scope) {
|
public static Dependency withId(String id, String groupId, String artifactId, String version, String scope) {
|
||||||
return withId(id, groupId, artifactId, version, scope, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dependency withId(String id, String groupId, String artifactId, String version, String scope,
|
|
||||||
String classifier) {
|
|
||||||
Dependency dependency = new Dependency();
|
Dependency dependency = new Dependency();
|
||||||
dependency.setId(id);
|
dependency.setId(id);
|
||||||
dependency.groupId = groupId;
|
dependency.groupId = groupId;
|
||||||
dependency.artifactId = artifactId;
|
dependency.artifactId = artifactId;
|
||||||
dependency.version = version;
|
dependency.version = version;
|
||||||
dependency.scope = (scope != null) ? scope : SCOPE_COMPILE;
|
dependency.scope = (scope != null) ? scope : SCOPE_COMPILE;
|
||||||
dependency.classifier = classifier;
|
|
||||||
return dependency;
|
return dependency;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,8 +526,6 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
*/
|
*/
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
private String classifier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The starter setting to use for the mapping or {@code null} to use the default.
|
* The starter setting to use for the mapping or {@code null} to use the default.
|
||||||
*/
|
*/
|
||||||
@@ -561,14 +558,6 @@ public class Dependency extends MetadataElement implements Describable {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassifier() {
|
|
||||||
return this.classifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClassifier(String classifier) {
|
|
||||||
this.classifier = classifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getStarter() {
|
public Boolean getStarter() {
|
||||||
return this.starter;
|
return this.starter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -46,8 +46,8 @@ public final class MetadataBuildItemMapper {
|
|||||||
? VersionReference.ofValue(dependency.getVersion()) : null;
|
? VersionReference.ofValue(dependency.getVersion()) : null;
|
||||||
return io.spring.initializr.generator.buildsystem.Dependency
|
return io.spring.initializr.generator.buildsystem.Dependency
|
||||||
.withCoordinates(dependency.getGroupId(), dependency.getArtifactId()).version(versionReference)
|
.withCoordinates(dependency.getGroupId(), dependency.getArtifactId()).version(versionReference)
|
||||||
.scope(toDependencyScope(dependency.getScope())).type(dependency.getType())
|
.scope(toDependencyScope(dependency.getScope())).classifier(dependency.getClassifier())
|
||||||
.classifier(dependency.getClassifier()).build();
|
.type(dependency.getType()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DependencyScope toDependencyScope(String scope) {
|
private static DependencyScope toDependencyScope(String scope) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2019 the original author or authors.
|
* Copyright 2012-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -45,7 +45,9 @@ class MetadataBuildItemResolverTests {
|
|||||||
void resoleDependencyWithMatchingEntry() {
|
void resoleDependencyWithMatchingEntry() {
|
||||||
InitializrMetadata metadata = new InitializrMetadata();
|
InitializrMetadata metadata = new InitializrMetadata();
|
||||||
DependencyGroup group = DependencyGroup.create("test");
|
DependencyGroup group = DependencyGroup.create("test");
|
||||||
group.getContent().add(Dependency.withId("test-dep", "com.example", "test", "1.0.0", "runtime", "classifier"));
|
Dependency target = Dependency.withId("test-dep", "com.example", "test", "1.0.0", "runtime");
|
||||||
|
target.setClassifier("test-jar");
|
||||||
|
group.getContent().add(target);
|
||||||
metadata.getDependencies().getContent().add(group);
|
metadata.getDependencies().getContent().add(group);
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
||||||
@@ -53,7 +55,7 @@ class MetadataBuildItemResolverTests {
|
|||||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||||
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
||||||
assertThat(dependency.getVersion()).hasToString("1.0.0");
|
assertThat(dependency.getVersion()).hasToString("1.0.0");
|
||||||
assertThat(dependency.getClassifier()).hasToString("classifier");
|
assertThat(dependency.getClassifier()).hasToString("test-jar");
|
||||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user