mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Polish
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
@@ -57,9 +56,8 @@ public abstract class GradleBuildWriter {
|
||||
* {@linkplain IndentingWriter writer}.
|
||||
* @param writer the writer to use
|
||||
* @param build the gradle build to write
|
||||
* @throws IOException if the writer fails to write the build
|
||||
*/
|
||||
public final void writeTo(IndentingWriter writer, GradleBuild build) throws IOException {
|
||||
public final void writeTo(IndentingWriter writer, GradleBuild build) {
|
||||
GradleBuildSettings settings = build.getSettings();
|
||||
writeImports(writer, build.tasks());
|
||||
writeBuildscript(writer, build);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class GradleConfiguration {
|
||||
|
||||
private final String name;
|
||||
|
||||
private Set<String> extendsFrom = new LinkedHashSet<>();
|
||||
private final Set<String> extendsFrom = new LinkedHashSet<>();
|
||||
|
||||
protected Builder(String name) {
|
||||
this.name = name;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.MavenRepository;
|
||||
import io.spring.initializr.generator.io.IndentingWriter;
|
||||
|
||||
@@ -36,9 +34,8 @@ public abstract class GradleSettingsWriter {
|
||||
* {@linkplain IndentingWriter writer}.
|
||||
* @param writer the writer to use
|
||||
* @param build the gradle build to write
|
||||
* @throws IOException if the writer fails to write the build
|
||||
*/
|
||||
public final void writeTo(IndentingWriter writer, GradleBuild build) throws IOException {
|
||||
public final void writeTo(IndentingWriter writer, GradleBuild build) {
|
||||
writePluginManagement(writer, build);
|
||||
writer.println("rootProject.name = " + wrapWithQuotes(build.getSettings().getArtifact()));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MavenBuild extends Build {
|
||||
|
||||
private final MavenResourceContainer testResources = new MavenResourceContainer();
|
||||
|
||||
private MavenPluginContainer plugins = new MavenPluginContainer();
|
||||
private final MavenPluginContainer plugins = new MavenPluginContainer();
|
||||
|
||||
public MavenBuild(BuildItemResolver buildItemResolver) {
|
||||
super(buildItemResolver);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.maven;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
@@ -55,9 +54,8 @@ public class MavenBuildWriter {
|
||||
* {@linkplain IndentingWriter writer}.
|
||||
* @param writer the writer to use
|
||||
* @param build the maven build to write
|
||||
* @throws IOException if the writer fails to write the build
|
||||
*/
|
||||
public void writeTo(IndentingWriter writer, MavenBuild build) throws IOException {
|
||||
public void writeTo(IndentingWriter writer, MavenBuild build) {
|
||||
MavenBuildSettings settings = build.getSettings();
|
||||
writeProject(writer, () -> {
|
||||
writeParent(writer, build);
|
||||
|
||||
@@ -216,7 +216,7 @@ public class MavenPlugin {
|
||||
|
||||
private String phase;
|
||||
|
||||
private List<String> goals = new ArrayList<>();
|
||||
private final List<String> goals = new ArrayList<>();
|
||||
|
||||
private ConfigurationBuilder configurationCustomization = null;
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.io.template;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -80,7 +79,7 @@ public class MustacheTemplateRenderer implements TemplateRenderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(String templateName, Map<String, ?> model) throws IOException {
|
||||
public String render(String templateName, Map<String, ?> model) {
|
||||
Template template = getTemplate(templateName);
|
||||
return template.execute(model);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class BulletedSection<T> implements Section {
|
||||
|
||||
private final String itemName;
|
||||
|
||||
private List<T> items = new ArrayList<>();
|
||||
private final List<T> items = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Create a new instance adding items in the model with the {@code items} key.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.io.text;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class MustacheSection implements Section {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PrintWriter writer) throws IOException {
|
||||
public void write(PrintWriter writer) {
|
||||
writer.println(this.templateRenderer.render(this.templateName, resolveModel(this.model)));
|
||||
}
|
||||
|
||||
|
||||
@@ -297,15 +297,15 @@ public final class Version implements Serializable, Comparable<Version> {
|
||||
}
|
||||
|
||||
private static int compareQualifier(Qualifier first, Qualifier second) {
|
||||
Integer firstIndex = getQualifierIndex(first.qualifier);
|
||||
Integer secondIndex = getQualifierIndex(second.qualifier);
|
||||
int firstIndex = getQualifierIndex(first.qualifier);
|
||||
int secondIndex = getQualifierIndex(second.qualifier);
|
||||
|
||||
// Unknown qualifier, alphabetic ordering
|
||||
if (firstIndex == -1 && secondIndex == -1) {
|
||||
return first.qualifier.compareTo(second.qualifier);
|
||||
}
|
||||
else {
|
||||
return firstIndex.compareTo(secondIndex);
|
||||
return Integer.compare(firstIndex, secondIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -37,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class Gradle3BuildWriterTests {
|
||||
|
||||
@Test
|
||||
void gradleBuildWithAnnotationProcessorDependency() throws IOException {
|
||||
void gradleBuildWithAnnotationProcessorDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("annotation-processor", "org.springframework.boot",
|
||||
"spring-boot-configuration-processor", DependencyScope.ANNOTATION_PROCESSOR);
|
||||
@@ -47,7 +46,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCompileDependency() throws IOException {
|
||||
void gradleBuildWithCompileDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", "org.springframework.boot", "spring-boot-starter", DependencyScope.COMPILE);
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -56,7 +55,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() throws IOException {
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -65,7 +64,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("driver", Dependency.withCoordinates("com.example", "jdbc-driver")
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME));
|
||||
@@ -74,7 +73,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithProvidedRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithProvidedRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("tomcat", "org.springframework.boot", "spring-boot-starter-tomcat",
|
||||
DependencyScope.PROVIDED_RUNTIME);
|
||||
@@ -84,7 +83,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTestCompileDependency() throws IOException {
|
||||
void gradleBuildWithTestCompileDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-test",
|
||||
DependencyScope.TEST_COMPILE);
|
||||
@@ -94,7 +93,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCompileOnlyDependency() throws IOException {
|
||||
void gradleBuildWithCompileOnlyDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-foobar",
|
||||
DependencyScope.COMPILE_ONLY);
|
||||
@@ -104,7 +103,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTestRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithTestRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("embed-mongo", "de.flapdoodle.embed", "de.flapdoodle.embed.mongo",
|
||||
DependencyScope.TEST_RUNTIME);
|
||||
@@ -114,7 +113,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithNonNullArtifactTypeDependency() throws IOException {
|
||||
void gradleBuildWithNonNullArtifactTypeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz"));
|
||||
@@ -124,7 +123,7 @@ class Gradle3BuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCustomDependencyConfiguration() throws IOException {
|
||||
void gradleBuildWithCustomDependencyConfiguration() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test",
|
||||
GradleDependency.withCoordinates("org.springframework.boot", "spring-boot-starter-foobar")
|
||||
@@ -134,7 +133,7 @@ class Gradle3BuildWriterTests {
|
||||
" myRuntime 'org.springframework.boot:spring-boot-starter-foobar'", "}");
|
||||
}
|
||||
|
||||
private List<String> generateBuild(GradleBuild build) throws IOException {
|
||||
private List<String> generateBuild(GradleBuild build) {
|
||||
Gradle3BuildWriter writer = new Gradle3BuildWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), build);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -43,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class GroovyDslGradleBuildWriterTests {
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCoordinates() throws IOException {
|
||||
void gradleBuildWithCoordinates() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().group("com.example").version("1.0.1-SNAPSHOT");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -51,7 +50,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSourceCompatibility() throws IOException {
|
||||
void gradleBuildWithSourceCompatibility() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().sourceCompatibility("11");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -59,7 +58,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithBuildscriptDependency() throws IOException {
|
||||
void gradleBuildWithBuildscriptDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add("maven-central");
|
||||
build.buildscript((buildscript) -> buildscript
|
||||
@@ -71,7 +70,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithBuildscriptExtProperty() throws IOException {
|
||||
void gradleBuildWithBuildscriptExtProperty() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add("maven-central");
|
||||
build.buildscript((buildscript) -> buildscript.ext("kotlinVersion", "'1.2.51'"));
|
||||
@@ -80,7 +79,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPlugin() throws IOException {
|
||||
void gradleBuildWithPlugin() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.plugins().add("java");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -88,7 +87,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPluginAndVersion() throws IOException {
|
||||
void gradleBuildWithPluginAndVersion() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.plugins().add("org.springframework.boot", (plugin) -> plugin.setVersion("2.1.0.RELEASE"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -97,7 +96,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithApplyPlugin() throws IOException {
|
||||
void gradleBuildWithApplyPlugin() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.plugins().apply("io.spring.dependency-management");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -105,7 +104,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithMavenCentralRepository() throws IOException {
|
||||
void gradleBuildWithMavenCentralRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add("maven-central");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -113,7 +112,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithRepository() throws IOException {
|
||||
void gradleBuildWithRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -122,7 +121,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSnapshotRepository() throws IOException {
|
||||
void gradleBuildWithSnapshotRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||
.snapshotsEnabled(true));
|
||||
@@ -132,7 +131,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPluginRepository() throws IOException {
|
||||
void gradleBuildWithPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories()
|
||||
.add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone"));
|
||||
@@ -141,7 +140,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskWithTypesCustomizedWithNestedAssignments() throws IOException {
|
||||
void gradleBuildWithTaskWithTypesCustomizedWithNestedAssignments() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customizeWithType("org.jetbrains.kotlin.gradle.tasks.KotlinCompile",
|
||||
(task) -> task.nested("kotlinOptions",
|
||||
@@ -155,7 +154,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskWithTypesAndShortTypes() throws IOException {
|
||||
void gradleBuildWithTaskWithTypesAndShortTypes() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customizeWithType("JavaCompile", (javaCompile) -> javaCompile.attribute("options.fork", "true"));
|
||||
assertThat(generateBuild(build)).doesNotContain("import JavaCompile")
|
||||
@@ -163,7 +162,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithInvocations() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithInvocations() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("asciidoctor", (task) -> {
|
||||
task.invoke("inputs.dir", "snippetsDir");
|
||||
@@ -174,7 +173,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithInvocationAndNoArgument() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithInvocationAndNoArgument() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("test", (task) -> task.invoke("myMethod"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -182,7 +181,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithAssignments() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithAssignments() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("compileKotlin", (task) -> {
|
||||
task.attribute("kotlinOptions.freeCompilerArgs", "['-Xjsr305=strict']");
|
||||
@@ -194,7 +193,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithNestedCustomization() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithNestedCustomization() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("compileKotlin",
|
||||
(compileKotlin) -> compileKotlin.nested("kotlinOptions", (kotlinOptions) -> {
|
||||
@@ -216,7 +215,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithVersionProperties() throws IOException {
|
||||
void gradleBuildWithVersionProperties() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.properties().version(VersionProperty.of("version.property", false), "1.2.3")
|
||||
.version(VersionProperty.of("internal.property", true), "4.5.6").version("external.property", "7.8.9");
|
||||
@@ -226,7 +225,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithVersionedDependency() throws IOException {
|
||||
void gradleBuildWithVersionedDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("kotlin-stdlib",
|
||||
Dependency.withCoordinates("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
|
||||
@@ -237,7 +236,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithExternalVersionedDependency() throws IOException {
|
||||
void gradleBuildWithExternalVersionedDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("acme",
|
||||
Dependency.withCoordinates("com.example", "acme")
|
||||
@@ -288,7 +287,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithAnnotationProcessorDependency() throws IOException {
|
||||
void gradleBuildWithAnnotationProcessorDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("annotation-processor", "org.springframework.boot",
|
||||
"spring-boot-configuration-processor", DependencyScope.ANNOTATION_PROCESSOR);
|
||||
@@ -298,7 +297,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCompileDependency() throws IOException {
|
||||
void gradleBuildWithCompileDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", "org.springframework.boot", "spring-boot-starter", DependencyScope.COMPILE);
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -307,7 +306,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() throws IOException {
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -316,7 +315,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("driver", Dependency.withCoordinates("com.example", "jdbc-driver")
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME));
|
||||
@@ -325,7 +324,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithProvidedRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithProvidedRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("tomcat", "org.springframework.boot", "spring-boot-starter-tomcat",
|
||||
DependencyScope.PROVIDED_RUNTIME);
|
||||
@@ -335,7 +334,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTestCompileDependency() throws IOException {
|
||||
void gradleBuildWithTestCompileDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-test",
|
||||
DependencyScope.TEST_COMPILE);
|
||||
@@ -345,7 +344,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCompileOnlyDependency() throws IOException {
|
||||
void gradleBuildWithCompileOnlyDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-foobar",
|
||||
DependencyScope.COMPILE_ONLY);
|
||||
@@ -355,7 +354,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTestRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithTestRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("embed-mongo", "de.flapdoodle.embed", "de.flapdoodle.embed.mongo",
|
||||
DependencyScope.TEST_RUNTIME);
|
||||
@@ -365,7 +364,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithExclusions() throws IOException {
|
||||
void gradleBuildWithExclusions() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test",
|
||||
Dependency.withCoordinates("com.example", "test").scope(DependencyScope.COMPILE).exclusions(
|
||||
@@ -378,7 +377,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCustomDependencyConfiguration() throws IOException {
|
||||
void gradleBuildWithCustomDependencyConfiguration() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test",
|
||||
GradleDependency.withCoordinates("org.springframework.boot", "spring-boot-starter-foobar")
|
||||
@@ -389,7 +388,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithNonNullArtifactTypeDependency() throws IOException {
|
||||
void gradleBuildWithNonNullArtifactTypeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz"));
|
||||
@@ -399,7 +398,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithBom() throws IOException {
|
||||
void gradleBuildWithBom() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.boms().add("test", BillOfMaterials.withCoordinates("com.example", "my-project-dependencies")
|
||||
.version(VersionReference.ofValue("1.0.0.RELEASE")));
|
||||
@@ -409,7 +408,7 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithOrderedBoms() throws IOException {
|
||||
void gradleBuildWithOrderedBoms() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.boms().add("bom1", BillOfMaterials.withCoordinates("com.example", "my-project-dependencies")
|
||||
.version(VersionReference.ofValue("1.0.0.RELEASE")).order(5));
|
||||
@@ -422,14 +421,14 @@ class GroovyDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCustomVersion() throws IOException {
|
||||
void gradleBuildWithCustomVersion() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().version("1.2.4.RELEASE");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).contains("version = '1.2.4.RELEASE'");
|
||||
}
|
||||
|
||||
private List<String> generateBuild(GradleBuild build) throws IOException {
|
||||
private List<String> generateBuild(GradleBuild build) {
|
||||
GradleBuildWriter writer = new GroovyDslGradleBuildWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), build);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -36,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class GroovyDslGradleSettingsWriterTests {
|
||||
|
||||
@Test
|
||||
void gradleBuildWithMavenCentralPluginRepository() throws IOException {
|
||||
void gradleBuildWithMavenCentralPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add("maven-central");
|
||||
List<String> lines = generateSettings(build);
|
||||
@@ -45,14 +44,14 @@ class GroovyDslGradleSettingsWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithoutPluginRepository() throws IOException {
|
||||
void gradleBuildWithoutPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
List<String> lines = generateSettings(build);
|
||||
assertThat(lines).doesNotContain("pluginManagement");
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPluginRepository() throws IOException {
|
||||
void gradleBuildWithPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add(MavenRepository
|
||||
.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone").name("Spring Milestones"));
|
||||
@@ -66,7 +65,7 @@ class GroovyDslGradleSettingsWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSnapshotPluginRepository() throws IOException {
|
||||
void gradleBuildWithSnapshotPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories()
|
||||
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||
@@ -81,14 +80,14 @@ class GroovyDslGradleSettingsWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void artifactIdShouldBeUsedAsTheRootProjectName() throws Exception {
|
||||
void artifactIdShouldBeUsedAsTheRootProjectName() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().artifact("my-application");
|
||||
List<String> lines = generateSettings(build);
|
||||
assertThat(lines).containsSequence("rootProject.name = 'my-application'");
|
||||
}
|
||||
|
||||
private List<String> generateSettings(GradleBuild build) throws IOException {
|
||||
private List<String> generateSettings(GradleBuild build) {
|
||||
GradleSettingsWriter writer = new GroovyDslGradleSettingsWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), build);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -42,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
class KotlinDslGradleBuildWriterTests {
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCoordinates() throws IOException {
|
||||
void gradleBuildWithCoordinates() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().group("com.example").version("1.0.1-SNAPSHOT");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -50,7 +49,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSourceCompatibility11() throws IOException {
|
||||
void gradleBuildWithSourceCompatibility11() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().sourceCompatibility("11");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -58,7 +57,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSourceCompatibility1Dot8() throws IOException {
|
||||
void gradleBuildWithSourceCompatibility1Dot8() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().sourceCompatibility("1.8");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -81,7 +80,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithBuiltinPlugin() throws IOException {
|
||||
void gradleBuildWithBuiltinPlugin() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.plugins().add("java");
|
||||
build.plugins().add("war");
|
||||
@@ -90,7 +89,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithKotlinPluginAndVersion() throws IOException {
|
||||
void gradleBuildWithKotlinPluginAndVersion() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.plugins().add("org.jetbrains.kotlin.jvm", (plugin) -> plugin.setVersion("1.3.21"));
|
||||
build.plugins().add("org.jetbrains.kotlin.plugin.spring", (plugin) -> plugin.setVersion("1.3.21"));
|
||||
@@ -100,7 +99,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPluginAndVersion() throws IOException {
|
||||
void gradleBuildWithPluginAndVersion() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.plugins().add("org.springframework.boot", (plugin) -> plugin.setVersion("2.1.0.RELEASE"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -116,7 +115,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithMavenCentralRepository() throws IOException {
|
||||
void gradleBuildWithMavenCentralRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add("maven-central");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -124,7 +123,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithRepository() throws IOException {
|
||||
void gradleBuildWithRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -133,7 +132,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSnapshotRepository() throws IOException {
|
||||
void gradleBuildWithSnapshotRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||
.snapshotsEnabled(true));
|
||||
@@ -143,7 +142,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPluginRepository() throws IOException {
|
||||
void gradleBuildWithPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories()
|
||||
.add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone"));
|
||||
@@ -152,7 +151,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskWithTypesCustomizedWithNestedAssignments() throws IOException {
|
||||
void gradleBuildWithTaskWithTypesCustomizedWithNestedAssignments() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customizeWithType("org.jetbrains.kotlin.gradle.tasks.KotlinCompile",
|
||||
(task) -> task.nested("kotlinOptions",
|
||||
@@ -166,7 +165,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskWithTypesAndShortTypes() throws IOException {
|
||||
void gradleBuildWithTaskWithTypesAndShortTypes() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customizeWithType("JavaCompile", (javaCompile) -> javaCompile.attribute("options.fork", "true"));
|
||||
assertThat(generateBuild(build)).doesNotContain("import JavaCompile")
|
||||
@@ -174,7 +173,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithInvocations() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithInvocations() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("asciidoctor", (task) -> {
|
||||
task.invoke("inputs.dir", "snippetsDir");
|
||||
@@ -186,7 +185,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithAssignments() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithAssignments() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("compileKotlin", (task) -> {
|
||||
task.attribute("kotlinOptions.freeCompilerArgs", "listOf(\"-Xjsr305=strict\")");
|
||||
@@ -199,7 +198,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTaskCustomizedWithNestedCustomization() throws IOException {
|
||||
void gradleBuildWithTaskCustomizedWithNestedCustomization() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.tasks().customize("compileKotlin",
|
||||
(compileKotlin) -> compileKotlin.nested("kotlinOptions", (kotlinOptions) -> {
|
||||
@@ -212,7 +211,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithExt() throws Exception {
|
||||
void gradleBuildWithExt() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.properties().property("java.version", "\"1.8\"").property("alpha", "file(\"build/example\")");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -221,7 +220,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithVersionProperties() throws IOException {
|
||||
void gradleBuildWithVersionProperties() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.properties().version(VersionProperty.of("version.property", false), "1.2.3")
|
||||
.version(VersionProperty.of("internal.property", true), "4.5.6").version("external.property", "7.8.9");
|
||||
@@ -231,7 +230,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithVersionedDependency() throws IOException {
|
||||
void gradleBuildWithVersionedDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("kotlin-stdlib",
|
||||
Dependency.withCoordinates("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
|
||||
@@ -242,7 +241,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithExternalVersionedDependency() throws IOException {
|
||||
void gradleBuildWithExternalVersionedDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("acme",
|
||||
Dependency.withCoordinates("com.example", "acme")
|
||||
@@ -254,7 +253,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithExtAndVersionProperties() throws Exception {
|
||||
void gradleBuildWithExtAndVersionProperties() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.properties().version(VersionProperty.of("test-version", true), "1.0").version("alpha-version", "0.1")
|
||||
.property("myProperty", "42");
|
||||
@@ -264,7 +263,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithConfiguration() throws Exception {
|
||||
void gradleBuildWithConfiguration() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.configurations().add("developmentOnly");
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -272,7 +271,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithConfigurationCustomization() throws Exception {
|
||||
void gradleBuildWithConfigurationCustomization() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.configurations().add("custom");
|
||||
build.configurations().customize("runtimeClasspath", (configuration) -> configuration.extendsFrom("custom"));
|
||||
@@ -283,7 +282,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithConfigurationCustomizations() throws Exception {
|
||||
void gradleBuildWithConfigurationCustomizations() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.configurations().add("custom");
|
||||
build.configurations().customize("runtimeClasspath", (configuration) -> configuration.extendsFrom("custom"));
|
||||
@@ -296,7 +295,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithAnnotationProcessorDependency() throws IOException {
|
||||
void gradleBuildWithAnnotationProcessorDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("annotation-processor", "org.springframework.boot",
|
||||
"spring-boot-configuration-processor", DependencyScope.ANNOTATION_PROCESSOR);
|
||||
@@ -306,7 +305,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCompileDependency() throws IOException {
|
||||
void gradleBuildWithCompileDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", "org.springframework.boot", "spring-boot-starter", DependencyScope.COMPILE);
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -315,7 +314,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() throws IOException {
|
||||
void gradleBuildWithNoScopeDependencyDefaultsToCompile() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter"));
|
||||
List<String> lines = generateBuild(build);
|
||||
@@ -324,7 +323,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("driver", Dependency.withCoordinates("com.example", "jdbc-driver")
|
||||
.version(VersionReference.ofValue("1.0.0")).scope(DependencyScope.RUNTIME));
|
||||
@@ -333,7 +332,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithProvidedRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithProvidedRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("tomcat", "org.springframework.boot", "spring-boot-starter-tomcat",
|
||||
DependencyScope.PROVIDED_RUNTIME);
|
||||
@@ -343,7 +342,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTestCompileDependency() throws IOException {
|
||||
void gradleBuildWithTestCompileDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-test",
|
||||
DependencyScope.TEST_COMPILE);
|
||||
@@ -353,7 +352,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCompileOnlyDependency() throws IOException {
|
||||
void gradleBuildWithCompileOnlyDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-foobar",
|
||||
DependencyScope.COMPILE_ONLY);
|
||||
@@ -363,7 +362,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithTestRuntimeDependency() throws IOException {
|
||||
void gradleBuildWithTestRuntimeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("embed-mongo", "de.flapdoodle.embed", "de.flapdoodle.embed.mongo",
|
||||
DependencyScope.TEST_RUNTIME);
|
||||
@@ -373,7 +372,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithExclusions() throws IOException {
|
||||
void gradleBuildWithExclusions() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test",
|
||||
Dependency.withCoordinates("com.example", "test").scope(DependencyScope.COMPILE).exclusions(
|
||||
@@ -386,7 +385,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCustomDependencyConfiguration() throws IOException {
|
||||
void gradleBuildWithCustomDependencyConfiguration() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("test",
|
||||
GradleDependency.withCoordinates("org.springframework.boot", "spring-boot-starter-foobar")
|
||||
@@ -397,7 +396,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithNonNullArtifactTypeDependency() throws IOException {
|
||||
void gradleBuildWithNonNullArtifactTypeDependency() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
||||
.scope(DependencyScope.COMPILE).type("tar.gz"));
|
||||
@@ -407,7 +406,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithBom() throws IOException {
|
||||
void gradleBuildWithBom() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.boms().add("test", BillOfMaterials.withCoordinates("com.example", "my-project-dependencies")
|
||||
.version(VersionReference.ofValue("1.0.0.RELEASE")));
|
||||
@@ -417,7 +416,7 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithOrderedBoms() throws IOException {
|
||||
void gradleBuildWithOrderedBoms() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.boms().add("bom1", BillOfMaterials.withCoordinates("com.example", "my-project-dependencies")
|
||||
.version(VersionReference.ofValue("1.0.0.RELEASE")).order(5));
|
||||
@@ -430,14 +429,14 @@ class KotlinDslGradleBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithCustomVersion() throws IOException {
|
||||
void gradleBuildWithCustomVersion() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().version("1.2.4.RELEASE");
|
||||
List<String> lines = generateBuild(build);
|
||||
assertThat(lines).contains("version = \"1.2.4.RELEASE\"");
|
||||
}
|
||||
|
||||
private List<String> generateBuild(GradleBuild build) throws IOException {
|
||||
private List<String> generateBuild(GradleBuild build) {
|
||||
GradleBuildWriter writer = new KotlinDslGradleBuildWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), build);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -35,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class KotlinDslGradleSettingsWriterTests {
|
||||
|
||||
@Test
|
||||
void gradleBuildWithMavenCentralPluginRepository() throws IOException {
|
||||
void gradleBuildWithMavenCentralPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add("maven-central");
|
||||
List<String> lines = generateSettings(build);
|
||||
@@ -44,14 +43,14 @@ class KotlinDslGradleSettingsWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithoutPluginRepository() throws IOException {
|
||||
void gradleBuildWithoutPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
List<String> lines = generateSettings(build);
|
||||
assertThat(lines).doesNotContain("pluginManagement");
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithPluginRepository() throws IOException {
|
||||
void gradleBuildWithPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add(MavenRepository
|
||||
.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone").name("Spring Milestones"));
|
||||
@@ -65,7 +64,7 @@ class KotlinDslGradleSettingsWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildWithSnapshotPluginRepository() throws IOException {
|
||||
void gradleBuildWithSnapshotPluginRepository() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories()
|
||||
.add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||
@@ -80,14 +79,14 @@ class KotlinDslGradleSettingsWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void artifactIdShouldBeUsedAsTheRootProjectName() throws Exception {
|
||||
void artifactIdShouldBeUsedAsTheRootProjectName() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().artifact("my-application");
|
||||
List<String> lines = generateSettings(build);
|
||||
assertThat(lines).containsSequence("rootProject.name = \"my-application\"");
|
||||
}
|
||||
|
||||
private List<String> generateSettings(GradleBuild build) throws IOException {
|
||||
private List<String> generateSettings(GradleBuild build) {
|
||||
GradleSettingsWriter writer = new KotlinDslGradleSettingsWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), build);
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class MavenBuildWriterTests {
|
||||
|
||||
@Test
|
||||
void basicPom() throws Exception {
|
||||
void basicPom() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").version("1.0.1-SNAPSHOT");
|
||||
generatePom(build, (pom) -> {
|
||||
@@ -52,7 +52,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithNameAndDescription() throws Exception {
|
||||
void pomWithNameAndDescription() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").name("demo project").description("A demo project");
|
||||
generatePom(build, (pom) -> {
|
||||
@@ -66,7 +66,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithParent() throws Exception {
|
||||
void pomWithParent() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").parent("org.springframework.boot",
|
||||
"spring-boot-starter-parent", "2.1.0.RELEASE");
|
||||
@@ -78,14 +78,14 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPackaging() throws Exception {
|
||||
void pomWithPackaging() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").packaging("war");
|
||||
generatePom(build, (pom) -> assertThat(pom).textAtPath("/project/packaging").isEqualTo("war"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithProperties() throws Exception {
|
||||
void pomWithProperties() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.properties().property("java.version", "1.8").property("alpha", "a");
|
||||
@@ -96,7 +96,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithVersionProperties() throws Exception {
|
||||
void pomWithVersionProperties() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.properties().version(VersionProperty.of("version.property", false), "1.2.3")
|
||||
.version(VersionProperty.of("internal.property", true), "4.5.6").version("external.property", "7.8.9");
|
||||
@@ -108,7 +108,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithAnnotationProcessorDependency() throws Exception {
|
||||
void pomWithAnnotationProcessorDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("annotation-processor", "org.springframework.boot",
|
||||
@@ -124,7 +124,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithCompileOnlyDependency() throws Exception {
|
||||
void pomWithCompileOnlyDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("foo-bar", "org.springframework.boot", "spring-boot-foo-bar",
|
||||
@@ -140,7 +140,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithCompileDependency() throws Exception {
|
||||
void pomWithCompileDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("root", "org.springframework.boot", "spring-boot-starter", DependencyScope.COMPILE);
|
||||
@@ -155,7 +155,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithNoScopeDependencyDefaultsToCompile() throws Exception {
|
||||
void pomWithNoScopeDependencyDefaultsToCompile() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter"));
|
||||
@@ -170,7 +170,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithRuntimeDependency() throws Exception {
|
||||
void pomWithRuntimeDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("hikari", "com.zaxxer", "HikariCP", DependencyScope.RUNTIME);
|
||||
@@ -185,7 +185,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithProvidedRuntimeDependency() throws Exception {
|
||||
void pomWithProvidedRuntimeDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("tomcat", "org.springframework.boot", "spring-boot-starter-tomcat",
|
||||
@@ -201,7 +201,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithTestCompileDependency() throws Exception {
|
||||
void pomWithTestCompileDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("test", "org.springframework.boot", "spring-boot-starter-test",
|
||||
@@ -217,7 +217,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithTestRuntimeDependency() throws Exception {
|
||||
void pomWithTestRuntimeDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("embed-mongo", "de.flapdoodle.embed", "de.flapdoodle.embed.mongo",
|
||||
@@ -233,7 +233,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithExclusions() throws Exception {
|
||||
void pomWithExclusions() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("test",
|
||||
@@ -258,7 +258,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithOptionalDependency() throws Exception {
|
||||
void pomWithOptionalDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("annotation-processor",
|
||||
@@ -275,7 +275,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithNonNullArtifactTypeDependency() throws Exception {
|
||||
void pomWithNonNullArtifactTypeDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.dependencies().add("root", Dependency.withCoordinates("org.springframework.boot", "spring-boot-starter")
|
||||
@@ -287,7 +287,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithBom() throws Exception {
|
||||
void pomWithBom() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.boms().add("test", BillOfMaterials.withCoordinates("com.example", "my-project-dependencies")
|
||||
@@ -299,7 +299,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithOrderedBoms() throws Exception {
|
||||
void pomWithOrderedBoms() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.boms().add("bom1", BillOfMaterials.withCoordinates("com.example", "my-project-dependencies")
|
||||
@@ -325,7 +325,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithResources() throws Exception {
|
||||
void pomWithResources() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.resources().add("src/main/custom", (resource) -> resource.includes("**/*.properties"));
|
||||
generatePom(build, (pom) -> {
|
||||
@@ -340,7 +340,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithTestResources() throws Exception {
|
||||
void pomWithTestResources() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.testResources().add("src/test/custom",
|
||||
(resource) -> resource.excludes("**/*.gen").filtering(true).targetPath("test"));
|
||||
@@ -357,7 +357,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPlugin() throws Exception {
|
||||
void pomWithPlugin() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.plugins().add("org.springframework.boot", "spring-boot-maven-plugin");
|
||||
@@ -371,7 +371,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPluginWithConfiguration() throws Exception {
|
||||
void pomWithPluginWithConfiguration() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.plugins().add("org.jetbrains.kotlin", "kotlin-maven-plugin",
|
||||
@@ -392,7 +392,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPluginWithExecution() throws Exception {
|
||||
void pomWithPluginWithExecution() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.plugins().add("org.asciidoctor", "asciidoctor-maven-plugin", (plugin) -> {
|
||||
@@ -422,7 +422,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPluginWithDependency() throws Exception {
|
||||
void pomWithPluginWithDependency() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.plugins().add("org.jetbrains.kotlin", "kotlin-maven-plugin",
|
||||
@@ -439,7 +439,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPluginWithExtensions() throws Exception {
|
||||
void pomWithPluginWithExtensions() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.plugins().add("com.example.demo", "demo-plugin", (plugin) -> plugin.extensions(true));
|
||||
@@ -452,14 +452,14 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithEmptyBuild() throws Exception {
|
||||
void pomWithEmptyBuild() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
generatePom(build, (pom) -> assertThat(pom).textAtPath("/project/build/").isNullOrEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithMavenCentral() throws Exception {
|
||||
void pomWithMavenCentral() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.repositories().add("maven-central");
|
||||
@@ -470,7 +470,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithRepository() throws Exception {
|
||||
void pomWithRepository() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-milestones", "https://repo.spring.io/milestone")
|
||||
@@ -486,7 +486,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithPluginRepository() throws Exception {
|
||||
void pomWithPluginRepository() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.pluginRepositories().add(MavenRepository
|
||||
@@ -504,7 +504,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithSnapshotRepository() throws Exception {
|
||||
void pomWithSnapshotRepository() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.repositories().add(MavenRepository.withIdAndUrl("spring-snapshots", "https://repo.spring.io/snapshot")
|
||||
@@ -520,7 +520,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithSnapshotPluginRepository() throws Exception {
|
||||
void pomWithSnapshotPluginRepository() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo");
|
||||
build.pluginRepositories()
|
||||
@@ -539,7 +539,7 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithCustomSourceDirectories() throws Exception {
|
||||
void pomWithCustomSourceDirectories() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").sourceDirectory("${project.basedir}/src/main/kotlin")
|
||||
.testSourceDirectory("${project.basedir}/src/test/kotlin");
|
||||
@@ -552,13 +552,13 @@ class MavenBuildWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithCustomVersion() throws Exception {
|
||||
void pomWithCustomVersion() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().version("1.2.4.RELEASE");
|
||||
generatePom(build, (pom) -> assertThat(pom).textAtPath("/project/version").isEqualTo("1.2.4.RELEASE"));
|
||||
}
|
||||
|
||||
private void generatePom(MavenBuild mavenBuild, Consumer<NodeAssert> consumer) throws Exception {
|
||||
private void generatePom(MavenBuild mavenBuild, Consumer<NodeAssert> consumer) {
|
||||
MavenBuildWriter writer = new MavenBuildWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
writer.writeTo(new IndentingWriter(out), mavenBuild);
|
||||
|
||||
Reference in New Issue
Block a user