mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Polish "Use Java configuration for Gradle build"
See gh-1427
This commit is contained in:
parent
a0d98918c5
commit
711d2c36da
@ -67,7 +67,6 @@ public abstract class GradleBuildWriter {
|
||||
writeProperty(writer, "version", settings.getVersion());
|
||||
writer.println();
|
||||
writeJavaSourceCompatibility(writer, settings);
|
||||
writer.println();
|
||||
writeConfigurations(writer, build.configurations());
|
||||
writeRepositories(writer, build);
|
||||
writeProperties(writer, build.properties());
|
||||
|
@ -92,6 +92,7 @@ public class GroovyDslGradleBuildWriter extends GradleBuildWriter {
|
||||
writer.indented(
|
||||
() -> writer.println(String.format("sourceCompatibility = '%s'", settings.getSourceCompatibility())));
|
||||
writer.println("}");
|
||||
writer.println("");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -86,6 +86,7 @@ public class KotlinDslGradleBuildWriter extends GradleBuildWriter {
|
||||
writer.indented(() -> writer.println(
|
||||
String.format("sourceCompatibility = %s", getJavaVersionConstant(settings.getSourceCompatibility()))));
|
||||
writer.println("}");
|
||||
writer.println();
|
||||
}
|
||||
|
||||
private String getJavaVersionConstant(String jvmVersion) {
|
||||
|
@ -16,11 +16,8 @@
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.gradle;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Set;
|
||||
|
||||
import io.spring.initializr.generator.io.IndentingWriter;
|
||||
import io.spring.initializr.generator.io.SimpleIndentStrategy;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -93,19 +90,4 @@ public abstract class GradleBuildWriterTests {
|
||||
|
||||
protected abstract String write(GradleBuild build);
|
||||
|
||||
/**
|
||||
* A helper method that tests if java configuration is written properly
|
||||
* @param format in which source compatibility must be written
|
||||
* @param jvmVersion for the java
|
||||
* @return the string representation for java configuration
|
||||
*/
|
||||
protected String javaConfigurationWriter(String format, String jvmVersion) {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
IndentingWriter writer = new IndentingWriter(stringWriter, new SimpleIndentStrategy("\t"));
|
||||
writer.println("java {");
|
||||
writer.indented(() -> writer.println(String.format(format, jvmVersion)));
|
||||
writer.println("}");
|
||||
return stringWriter.toString().replace("\r\n", "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,8 +52,11 @@ class GroovyDslGradleBuildWriterTests extends GradleBuildWriterTests {
|
||||
void gradleBuildWithSourceCompatibility() {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().sourceCompatibility("11");
|
||||
String javaConfiguration = javaConfigurationWriter("sourceCompatibility = '%s'", "11");
|
||||
assertThat(write(build)).contains(javaConfiguration);
|
||||
assertThat(write(build)).contains("""
|
||||
java {
|
||||
sourceCompatibility = '11'
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -60,8 +60,11 @@ class KotlinDslGradleBuildWriterTests extends GradleBuildWriterTests {
|
||||
void gradleBuildWithSourceCompatibility15(String sourceCompatibility, String javaVersionConstant) {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.settings().sourceCompatibility(sourceCompatibility);
|
||||
String javaConfiguration = javaConfigurationWriter("sourceCompatibility = %s", javaVersionConstant);
|
||||
assertThat(write(build)).contains(javaConfiguration);
|
||||
assertThat(write(build)).contains("""
|
||||
java {
|
||||
sourceCompatibility = %s
|
||||
}
|
||||
""".formatted(javaVersionConstant));
|
||||
}
|
||||
|
||||
static Stream<Arguments> sourceCompatibilityParameters() {
|
||||
|
Loading…
Reference in New Issue
Block a user