mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-26 14:15:53 +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
|
||||
that dependency.
|
||||
* 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
|
||||
that dependency is added.
|
||||
* 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");
|
||||
* 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 String type;
|
||||
|
||||
private final String classifier;
|
||||
|
||||
private final String type;
|
||||
|
||||
private final Set<Exclusion> exclusions;
|
||||
|
||||
protected Dependency(Builder<?> builder) {
|
||||
@@ -110,6 +110,14 @@ public class Dependency {
|
||||
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
|
||||
* should be used (i.e. {@code jar}).
|
||||
@@ -119,14 +127,6 @@ public class Dependency {
|
||||
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.
|
||||
* @return the exclusions to apply
|
||||
@@ -151,10 +151,10 @@ public class Dependency {
|
||||
|
||||
private DependencyScope scope;
|
||||
|
||||
private String classifier;
|
||||
|
||||
private String type;
|
||||
|
||||
private String classifier;
|
||||
|
||||
private Set<Exclusion> exclusions = new LinkedHashSet<>();
|
||||
|
||||
protected Builder(String groupId, String artifactId) {
|
||||
@@ -182,13 +182,13 @@ public class Dependency {
|
||||
return self();
|
||||
}
|
||||
|
||||
public B type(String type) {
|
||||
this.type = type;
|
||||
public B classifier(String classifier) {
|
||||
this.classifier = classifier;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B classifier(String classifier) {
|
||||
this.classifier = classifier;
|
||||
public B type(String type) {
|
||||
this.type = type;
|
||||
return self();
|
||||
}
|
||||
|
||||
@@ -208,8 +208,8 @@ public class Dependency {
|
||||
}
|
||||
|
||||
protected B initialize(Dependency dependency) {
|
||||
version(dependency.getVersion()).scope(dependency.getScope()).type(dependency.getType())
|
||||
.exclusions(dependency.getExclusions());
|
||||
version(dependency.getVersion()).scope(dependency.getScope()).classifier(dependency.getClassifier())
|
||||
.type(dependency.getType()).exclusions(dependency.getExclusions());
|
||||
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");
|
||||
* 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) {
|
||||
String quoteStyle = determineQuoteStyle(dependency.getVersion());
|
||||
String version = determineVersion(dependency.getVersion());
|
||||
String type = dependency.getType();
|
||||
String classifier = dependency.getClassifier();
|
||||
String type = dependency.getType();
|
||||
boolean hasExclusions = !dependency.getExclusions().isEmpty();
|
||||
writer.print(configurationForDependency(dependency));
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -149,8 +149,8 @@ public class KotlinDslGradleBuildWriter extends GradleBuildWriter {
|
||||
@Override
|
||||
protected void writeDependency(IndentingWriter writer, Dependency dependency) {
|
||||
String version = determineVersion(dependency.getVersion());
|
||||
String type = dependency.getType();
|
||||
String classifier = dependency.getClassifier();
|
||||
String type = dependency.getType();
|
||||
writer.print(configurationForDependency(dependency) + "(\"" + dependency.getGroupId() + ":"
|
||||
+ dependency.getArtifactId() + ((version != null) ? ":" + version : "")
|
||||
+ ((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");
|
||||
* 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}
|
||||
*/
|
||||
public static Builder from(Dependency dependency) {
|
||||
return new Builder(dependency.getGroupId(), dependency.getArtifactId()).initialize(dependency)
|
||||
.classifier(dependency.getClassifier());
|
||||
return new Builder(dependency.getGroupId(), dependency.getArtifactId()).initialize(dependency);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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");
|
||||
* 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.getScope()).isNull();
|
||||
assertThat(dependency.getVersion()).isNull();
|
||||
assertThat(dependency.getClassifier()).isNull();
|
||||
assertThat(dependency.getType()).isNull();
|
||||
assertThat(dependency.getExclusions()).isEmpty();
|
||||
}
|
||||
@@ -48,6 +49,19 @@ class DependencyTests {
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||
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.getExclusions()).isEmpty();
|
||||
}
|
||||
@@ -59,6 +73,7 @@ class DependencyTests {
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||
assertThat(dependency.getScope()).isNull();
|
||||
assertThat(dependency.getVersion()).isNull();
|
||||
assertThat(dependency.getClassifier()).isNull();
|
||||
assertThat(dependency.getType()).isEqualTo("test-zip");
|
||||
assertThat(dependency.getExclusions()).isEmpty();
|
||||
}
|
||||
@@ -71,6 +86,7 @@ class DependencyTests {
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("acme");
|
||||
assertThat(dependency.getScope()).isNull();
|
||||
assertThat(dependency.getVersion()).isNull();
|
||||
assertThat(dependency.getClassifier()).isNull();
|
||||
assertThat(dependency.getType()).isNull();
|
||||
assertThat(dependency.getExclusions()).containsExactly(new Exclusion("com.example", "exclude1"),
|
||||
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");
|
||||
* 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'", "}");
|
||||
}
|
||||
|
||||
@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
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
@@ -373,6 +363,14 @@ class GroovyDslGradleBuildWriterTests {
|
||||
" 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
|
||||
void gradleBuildWithExclusions() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
@@ -410,11 +408,11 @@ class GroovyDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("classifier"));
|
||||
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("test-jar"));
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("dependencies {",
|
||||
" implementation 'org.springframework.boot:spring-boot-starter:classifier@tar.gz'", "}");
|
||||
assertThat(lines).containsSequence("dependencies {", " implementation 'com.example:acme:test-jar@tar.gz'",
|
||||
"}");
|
||||
}
|
||||
|
||||
@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");
|
||||
* 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\")", "}");
|
||||
}
|
||||
|
||||
@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
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
@@ -381,6 +371,15 @@ class KotlinDslGradleBuildWriterTests {
|
||||
" 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
|
||||
void gradleBuildWithExclusions() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
@@ -418,11 +417,11 @@ class KotlinDslGradleBuildWriterTests {
|
||||
@Test
|
||||
void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("classifier"));
|
||||
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz").classifier("test-jar"));
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).containsSequence("dependencies {",
|
||||
" implementation(\"org.springframework.boot:spring-boot-starter:classifier@tar.gz\")", "}");
|
||||
assertThat(lines).containsSequence("dependencies {", " implementation(\"com.example:acme:test-jar@tar.gz\")",
|
||||
"}");
|
||||
}
|
||||
|
||||
@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");
|
||||
* 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
|
||||
void pomWithCompileOnlyDependency() {
|
||||
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
|
||||
void pomWithExclusions() {
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,24 +33,24 @@ class MavenDependencyTests {
|
||||
@Test
|
||||
void initializeFromStandardDependency() {
|
||||
Dependency original = Dependency.withCoordinates("com.example", "test")
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).type("zip")
|
||||
.classifier("classifier").build();
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).classifier("test-jar")
|
||||
.type("zip").build();
|
||||
MavenDependency dependency = MavenDependency.from(original).build();
|
||||
assertThat(original).isNotSameAs(dependency);
|
||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
||||
assertThat(dependency.getVersion()).isEqualTo(VersionReference.ofValue("1.0.0"));
|
||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||
assertThat(dependency.getClassifier()).isEqualTo("test-jar");
|
||||
assertThat(dependency.getType()).isEqualTo("zip");
|
||||
assertThat(dependency.getClassifier()).isEqualTo("classifier");
|
||||
assertThat(dependency.isOptional()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void initializeFromMavenDependency() {
|
||||
Dependency original = MavenDependency.withCoordinates("com.example", "test")
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).type("zip").optional(true)
|
||||
.classifier("classifier").build();
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME).classifier("test-jar")
|
||||
.type("zip").optional(true).build();
|
||||
MavenDependency dependency = MavenDependency.from(original).build();
|
||||
assertThat(original).isNotSameAs(dependency);
|
||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||
@@ -58,18 +58,8 @@ class MavenDependencyTests {
|
||||
assertThat(dependency.getVersion()).isEqualTo(VersionReference.ofValue("1.0.0"));
|
||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||
assertThat(dependency.getType()).isEqualTo("zip");
|
||||
assertThat(dependency.getClassifier()).isEqualTo("classifier");
|
||||
assertThat(dependency.getClassifier()).isEqualTo("test-jar");
|
||||
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");
|
||||
* 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 type;
|
||||
|
||||
private String classifier;
|
||||
|
||||
private String type;
|
||||
|
||||
private List<Mapping> mappings = new ArrayList<>();
|
||||
|
||||
private String scope = SCOPE_COMPILE;
|
||||
@@ -132,6 +132,7 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
this.groupId = dependency.groupId;
|
||||
this.artifactId = dependency.artifactId;
|
||||
this.version = dependency.version;
|
||||
this.classifier = dependency.classifier;
|
||||
this.type = dependency.type;
|
||||
this.mappings.addAll(dependency.mappings);
|
||||
this.scope = dependency.scope;
|
||||
@@ -145,7 +146,6 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
this.starter = dependency.starter;
|
||||
this.keywords.addAll(dependency.keywords);
|
||||
this.links.addAll(dependency.links);
|
||||
this.classifier = dependency.classifier;
|
||||
}
|
||||
|
||||
public void setScope(String scope) {
|
||||
@@ -328,6 +328,11 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
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() {
|
||||
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) {
|
||||
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.setId(id);
|
||||
dependency.groupId = groupId;
|
||||
dependency.artifactId = artifactId;
|
||||
dependency.version = version;
|
||||
dependency.scope = (scope != null) ? scope : SCOPE_COMPILE;
|
||||
dependency.classifier = classifier;
|
||||
return dependency;
|
||||
}
|
||||
|
||||
@@ -527,8 +526,6 @@ public class Dependency extends MetadataElement implements Describable {
|
||||
*/
|
||||
private String version;
|
||||
|
||||
private String classifier;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
public String getClassifier() {
|
||||
return this.classifier;
|
||||
}
|
||||
|
||||
public void setClassifier(String classifier) {
|
||||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
public Boolean getStarter() {
|
||||
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");
|
||||
* 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;
|
||||
return io.spring.initializr.generator.buildsystem.Dependency
|
||||
.withCoordinates(dependency.getGroupId(), dependency.getArtifactId()).version(versionReference)
|
||||
.scope(toDependencyScope(dependency.getScope())).type(dependency.getType())
|
||||
.classifier(dependency.getClassifier()).build();
|
||||
.scope(toDependencyScope(dependency.getScope())).classifier(dependency.getClassifier())
|
||||
.type(dependency.getType()).build();
|
||||
}
|
||||
|
||||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,7 +45,9 @@ class MetadataBuildItemResolverTests {
|
||||
void resoleDependencyWithMatchingEntry() {
|
||||
InitializrMetadata metadata = new InitializrMetadata();
|
||||
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.validate();
|
||||
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
|
||||
@@ -53,7 +55,7 @@ class MetadataBuildItemResolverTests {
|
||||
assertThat(dependency.getGroupId()).isEqualTo("com.example");
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("test");
|
||||
assertThat(dependency.getVersion()).hasToString("1.0.0");
|
||||
assertThat(dependency.getClassifier()).hasToString("classifier");
|
||||
assertThat(dependency.getClassifier()).hasToString("test-jar");
|
||||
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user