Skip to content

Add description to generated Gradle build files #1684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ private GradleBuild createGradleBuild(BuildItemResolver buildItemResolver,

@Bean
public BuildCustomizer<GradleBuild> defaultGradleBuildCustomizer(ProjectDescription description) {
return (build) -> build.settings().sourceCompatibility(description.getLanguage().jvmVersion());
return (build) -> build.settings()
.sourceCompatibility(description.getLanguage().jvmVersion())
.description(description.getDescription());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,14 @@ void junitPlatformIsConfiguredWithCompatibleVersion() {
.containsSequence("tasks.withType<Test> {", " useJUnitPlatform()", "}");
}

@Test
void descriptionIsWrittenWhenBuildingGradleProject() {
MutableProjectDescription description = new MutableProjectDescription();
description.setDescription("Test Project");
description.setPlatformVersion(Version.parse("2.4.0"));
description.setLanguage(new JavaLanguage());
ProjectStructure project = this.projectTester.generate(description);
assertThat(project).textFile("build.gradle.kts").contains("description = \"Test Project\"");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,14 @@ void gradleAnnotationProcessorScopeCustomizerIsContributed() {
(context) -> assertThat(context).hasSingleBean(GradleAnnotationProcessorScopeBuildCustomizer.class));
}

@Test
void descriptionIsWrittenWhenBuildingGradleProject() {
MutableProjectDescription description = new MutableProjectDescription();
description.setDescription("Test Project");
description.setPlatformVersion(Version.parse("2.4.0"));
description.setLanguage(new JavaLanguage());
ProjectStructure project = this.projectTester.generate(description);
assertThat(project).textFile("build.gradle").contains("description = 'Test Project'");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {

group = 'com.example'
version = '0.0.1-SNAPSHOT'
description = 'Demo project for Spring Boot'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {

group = "com.example"
version = "0.0.1-SNAPSHOT"
description = "Demo project for Spring Boot"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ public class GradleBuildSettings extends BuildSettings {

private final List<PluginMapping> pluginMappings;

private final String description;

protected GradleBuildSettings(Builder builder) {
super(builder);
this.sourceCompatibility = builder.sourceCompatibility;
this.pluginMappings = new ArrayList<>(builder.pluginMappings);
this.description = builder.description;
}

/**
Expand All @@ -55,6 +58,14 @@ public List<PluginMapping> getPluginMappings() {
return this.pluginMappings;
}

/**
* Return a human-readable description of the project.
* @return the description of the project or {@code null}
*/
public String getDescription() {
return this.description;
}

/**
* Builder for {@link GradleBuildSettings}.
*/
Expand All @@ -64,6 +75,8 @@ public static class Builder extends BuildSettings.Builder<Builder> {

private final List<PluginMapping> pluginMappings = new ArrayList<>();

private String description;

/**
* Set the java version compatibility to use when compiling Java source.
* @param sourceCompatibility java version compatibility
Expand All @@ -89,6 +102,16 @@ public Builder mapPlugin(String id, Dependency pluginDependency) {
return this;
}

/**
* Set a human-readable description of the project.
* @param description the description of the project
* @return this for method chaining
*/
public Builder description(String description) {
this.description = description;
return this;
}

/**
* Build a {@link GradleBuildSettings} with the current state of this builder.
* @return a {@link GradleBuildSettings}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public final void writeTo(IndentingWriter writer, GradleBuild build) {
writePlugins(writer, build);
writeProperty(writer, "group", settings.getGroup());
writeProperty(writer, "version", settings.getVersion());
writeProperty(writer, "description", settings.getDescription());
writer.println();
writeJavaSourceCompatibility(writer, settings);
writeToolchain(writer, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@ void shouldCustomizeExtensions() {
}""");
}

@Test
void gradleBuildWithDescription() {
GradleBuild build = new GradleBuild();
build.settings().description("Demo for test");
String written = write(build);
assertThat(written).contains("description = 'Demo for test'");
}

protected String write(GradleBuild build) {
return write(new GroovyDslGradleBuildWriter(), build);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,14 @@ void shouldCustomizeExtensions() {
}""");
}

@Test
void gradleBuildWithDescription() {
GradleBuild build = new GradleBuild();
build.settings().description("Demo for test");
String written = write(build);
assertThat(written).contains("description = \"Demo for test\"");
}

protected String write(GradleBuild build) {
return write(new KotlinDslGradleBuildWriter(), build);
}
Expand Down