Skip to content

Commit

Permalink
Remove support for applying the conventions as a project plugin
Browse files Browse the repository at this point in the history
Closes gh-75
  • Loading branch information
wilkinsona committed Apr 5, 2024
1 parent fb71d4b commit 232f03d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 105 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,8 @@ pluginManagement {
```

In the example above, `gradlePluginPortal()` is declared to allow other plugins to continue to be resolved from the portal.
The second step in applying the plugin depends on the version of Gradle that you are using.

#### Gradle 5.x

The plugin should be applied in `build.gradle` of the root project, alongside the `com.gradle.build-scan` plugin:

```groovy
plugins {
// …
id "com.gradle.build-scan" version "<<version>>"
id "io.spring.ge.conventions" version "<<version>>"
// …
}
```

#### Gradle 6.x and later

The plugin should be applied in `settings.gradle`, alongside the `com.gradle.enterprise` plugin:
Now apply the plugin in `settings.gradle`, alongside the `com.gradle.enterprise` plugin:

```groovy
plugins {
Expand All @@ -150,4 +134,4 @@ plugins {
id "io.spring.ge.conventions" version "<<version>>"
// …
}
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.gradle.scan.plugin.BuildScanExtension;
import org.gradle.StartParameter;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.initialization.Settings;
import org.gradle.api.internal.ProcessOperations;

Expand All @@ -35,7 +34,7 @@
*
* @author Andy Wilkinson
*/
public class GradleEnterpriseConventionsPlugin implements Plugin<Object> {
public class GradleEnterpriseConventionsPlugin implements Plugin<Settings> {

private final ProcessOperations processOperations;

Expand All @@ -45,16 +44,7 @@ public GradleEnterpriseConventionsPlugin(ProcessOperations processOperations) {
}

@Override
public void apply(Object target) {
if (target instanceof Settings) {
apply((Settings) target);
}
else if (target instanceof Project) {
apply((Project) target);
}
}

private void apply(Settings settings) {
public void apply(Settings settings) {
settings.getPlugins().withType(GradleEnterprisePlugin.class, (plugin) -> {
GradleEnterpriseExtension extension = settings.getExtensions().getByType(GradleEnterpriseExtension.class);
configureBuildScanConventions(extension.getBuildScan(), settings.getStartParameter(),
Expand All @@ -66,14 +56,6 @@ private void apply(Settings settings) {
}
}

private void apply(Project project) {
project.getPlugins()
.withId("com.gradle.build-scan",
(plugin) -> configureBuildScanConventions(
project.getExtensions().getByType(BuildScanExtension.class),
project.getGradle().getStartParameter(), project.getRootDir()));
}

private void configureBuildScanConventions(BuildScanExtension buildScan, StartParameter startParameter,
File rootDir) {
if (startParameter.isNoBuildScan() || containsPropertiesTask(startParameter)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,113 +43,62 @@
class GradleEnterpriseConventionsPluginIntegrationTests {

@Test
void givenGradle6WhenThePluginIsAppliedThenBuildScanConventionsAreApplied(@TempDir File projectDir) {
prepareGradle6Project(projectDir);
void whenThePluginIsAppliedThenBuildScanConventionsAreApplied(@TempDir File projectDir) {
prepareProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "verifyBuildScanConfig");
assertThat(result.getOutput()).contains("Build scan server: https://ge.spring.io");
assertThat(result.getOutput()).contains("Capture task input files: true");
}

@Test
void givenGradle6WhenThePluginIsAppliedThenBuildCacheConventionsAreApplied(@TempDir File projectDir) {
prepareGradle6Project(projectDir);
void whenThePluginIsAppliedThenBuildCacheConventionsAreApplied(@TempDir File projectDir) {
prepareProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "verifyBuildCacheConfig");
assertThat(result.getOutput()).contains("Build cache remote: https://ge.spring.io/cache/");
}

@Test
void givenGradle6WhenThePluginIsAppliedAndBuildScansAreDisabledThenBuildScanConventionsAreNotApplied(
@TempDir File projectDir) {
prepareGradle6Project(projectDir);
void whenThePluginIsAppliedAndBuildScansAreDisabledThenBuildScanConventionsAreNotApplied(@TempDir File projectDir) {
prepareProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "verifyBuildScanConfig", "--no-scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: false");
}

@Test
void givenGradle6WhenThePluginIsAppliedAndPropertiesTaskIsExecutedThenBuildScanConventionsAreNotApplied(
void whenThePluginIsAppliedAndPropertiesTaskIsExecutedThenBuildScanConventionsAreNotApplied(
@TempDir File projectDir) {
prepareGradle6Project(projectDir);
prepareProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "properties", "verifyBuildScanConfig", "--no-scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: false");
}

@Test
void givenGradle6MulitProjectBuildWhenThePluginIsAppliedAndPropertiesTaskIsExecutedThenBuildScanConventionsAreNotApplied(
void givenMultiProjectBuildWhenThePluginIsAppliedAndPropertiesTaskIsExecutedThenBuildScanConventionsAreNotApplied(
@TempDir File projectDir) {
prepareGradle6MultiProject(projectDir);
prepareMultiModuleProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "sub:properties", "sub:verifyBuildScanConfig", "--no-scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: false");
}

@Test
void givenGradle6WhenThePluginIsAppliedAndScanIsSpecifiedThenServerIsNotCustomized(@TempDir File projectDir) {
prepareGradle6Project(projectDir);
void whenThePluginIsAppliedAndScanIsSpecifiedThenServerIsNotCustomized(@TempDir File projectDir) {
prepareProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "verifyBuildScanConfig", "--scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: true");
}

@Test
void givenGradle6WhenThePluginIsAppliedAndBuildCacheIsDisabledThenBuildCacheConventionsAreNotApplied(
@TempDir File projectDir) {
prepareGradle6Project(projectDir);
void whenThePluginIsAppliedAndBuildCacheIsDisabledThenBuildCacheConventionsAreNotApplied(@TempDir File projectDir) {
prepareProject(projectDir);
BuildResult result = build(projectDir, "6.0.1", "verifyBuildCacheConfig", "--no-build-cache");
assertThat(result.getOutput()).contains("Build cache remote: null");
}

@Test
void givenGradle5WhenThePluginIsAppliedThenBuildScanConventionsAreApplied(@TempDir File projectDir) {
prepareGradle5Project(projectDir);
BuildResult result = build(projectDir, "5.6.4", "verifyBuildScanConfig");
assertThat(result.getOutput()).contains("Build scan server: https://ge.spring.io");
assertThat(result.getOutput()).contains("Capture task input files: true");
}

@Test
void givenGradle5WhenThePluginIsAppliedAndBuildScansAreDisabledThenBuildScanConventionsAreNotApplied(
@TempDir File projectDir) {
prepareGradle5Project(projectDir);
BuildResult result = build(projectDir, "5.6.4", "verifyBuildScanConfig", "--no-scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: false");
}

@Test
void givenGradle5WhenThePluginIsAppliedAndPropertiesTaskIsExecutedThenBuildScanConventionsAreNotApplied(
@TempDir File projectDir) {
prepareGradle5Project(projectDir);
BuildResult result = build(projectDir, "5.6.4", "properties", "verifyBuildScanConfig", "--no-scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: false");
}

@Test
void givenGradle5WhenThePluginIsAppliedAndScanIsSpecifiedThenServerIsNotCustomized(@TempDir File projectDir) {
prepareGradle5Project(projectDir);
BuildResult result = build(projectDir, "5.6.4", "verifyBuildScanConfig", "--scan");
assertThat(result.getOutput()).contains("Build scan server: null");
assertThat(result.getOutput()).contains("Capture task input files: true");
}

private void prepareGradle5Project(File projectDir) {
write(new File(projectDir, "build.gradle"), (writer) -> {
writer.println("plugins {");
writer.println(" id 'com.gradle.build-scan'");
writer.println(" id 'io.spring.ge.conventions' version '" + version() + "'");
writer.println("}");
writer.println("task verifyBuildScanConfig {");
writer.println(" doFirst {");
writer.println(" println \"Build scan server: ${buildScan.server}\"");
writer.println(" println \"Capture task input files: ${buildScan.captureTaskInputFiles}\"");
writer.println(" }");
writer.println("}");
});
}

private void prepareGradle6Project(File projectDir) {
private void prepareProject(File projectDir) {
write(new File(projectDir, "gradle.properties"), (writer) -> writer.println("org.gradle.caching=true"));
write(new File(projectDir, "settings.gradle"), (writer) -> {
writer.println("plugins {");
Expand All @@ -174,7 +123,7 @@ private void prepareGradle6Project(File projectDir) {
});
}

private void prepareGradle6MultiProject(File projectDir) {
private void prepareMultiModuleProject(File projectDir) {
write(new File(projectDir, "gradle.properties"), (writer) -> writer.println("org.gradle.caching=true"));
write(new File(projectDir, "settings.gradle"), (writer) -> {
writer.println("plugins {");
Expand Down

0 comments on commit 232f03d

Please sign in to comment.