Skip to content

Commit 5d73689

Browse files
authored
Define more conventions for all GradleX projects (#60)
* Define more conventions for all GradleX projects * Update plugin ID * Update Readme
1 parent 7eaa8bc commit 5d73689

22 files changed

+1071
-219
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@
33
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fgradlex-org%2Fplugin-publish-conventions%2Fbadge%3Fref%3Dmain&style=flat)](https://actions-badge.atrox.dev/gradlex-org/plugin-publish-conventions/goto?ref=main)
44
[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v?label=Plugin%20Portal&metadataUrl=https%3A%2F%2Fplugins.gradle.org%2Fm2%2Forg%2Fgradlex%2Finternal%2Fplugin-publish-conventions%2Forg.gradlex.internal.plugin-publish-conventions.gradle.plugin%2Fmaven-metadata.xml)](https://plugins.gradle.org/plugin/org.gradlex.internal.plugin-publish-conventions)
55

6-
**Note: This plugin is currently to be used within the GradleX organization only to publish `org.gradlex` plugins**
6+
**Note: This plugin is currently to be used within the GradleX organization only to develop `org.gradlex` plugins**
77

88
# Usage
99

10+
**settings.gradle.kts**
1011
```kotlin
1112
plugins {
12-
id("org.gradlex.internal.plugin-publish-conventions")
13+
id("org.gradlex.internal-build-conventions") version "0.7"
1314
}
15+
```
1416

15-
pluginPublishConventions {
16-
id("${project.group}.${project.name}")
17-
implementationClass("org.gradlex.buildparameters.BuildParametersPlugin")
18-
displayName("Build Parameters Gradle Plugin")
19-
description("Compile-safe access to parameters supplied to a Gradle build.")
20-
tags("gradlex", "parameters", "build parameters")
17+
**build.gradle.kts**
18+
```kotlin
19+
publishingConventions {
20+
pluginPortal("${project.group}.${project.name}") {
21+
implementationClass("org.gradlex.buildparameters.BuildParametersPlugin")
22+
displayName("Build Parameters Gradle Plugin")
23+
description("Compile-safe access to parameters supplied to a Gradle build.")
24+
tags("gradlex", "parameters", "build parameters")
25+
}
2126
gitHub("https://github.com/gradlex-org/build-parameters")
2227
// ...
2328
}
29+
testingConventions {
30+
testGradleVersions("6.8.3", "6.9.4", "7.0.2", "8.0.2", "8.14.3")
31+
}
2432
```
2533

2634
# Disclaimer

build.gradle.kts

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,97 @@
11
plugins {
22
id("java-gradle-plugin")
3+
id("org.gradlex.build-parameters") version "1.4.4"
34
id("org.gradlex.internal.plugin-publish-conventions") version "0.6"
45
}
56

6-
group = "org.gradlex"
77
version = "0.7"
88

9-
java {
10-
toolchain.languageVersion = JavaLanguageVersion.of(11)
9+
dependencies {
10+
implementation("com.diffplug.spotless:spotless-plugin-gradle:8.0.0") {
11+
// Exclude transitive dependencies of JGit as we do not need git functionality.
12+
// We can't exclude JGit itself as types are referenced in SpotlessTask.class.
13+
exclude("com.googlecode.javaewah", "JavaEWAH")
14+
exclude("commons-codec", "commons-codec")
15+
exclude("org.slf4j", "slf4j-api")
16+
}
17+
implementation("com.gradle.publish:plugin-publish-plugin:2.0.0")
18+
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.4.0")
19+
implementation("com.gradle:develocity-gradle-plugin:4.2.2")
20+
implementation("com.gradleup.nmcp:nmcp:1.2.0")
21+
implementation("org.asciidoctor:asciidoctor-gradle-jvm:4.0.5")
22+
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.4")
23+
implementation("org.gradlex:reproducible-builds:1.1")
24+
}
25+
26+
dependencies.constraints {
27+
implementation("org.jetbrains:annotations:13.0!!") {
28+
because("This version is enforced by Gradle through the Kotlin plugin")
29+
}
30+
}
31+
32+
// ==== the following can be remove once we update the onventions to '0.7'
33+
group = "org.gradlex"
34+
java { toolchain.languageVersion = JavaLanguageVersion.of(17) }
35+
tasks.checkstyleMain { exclude("buildparameters/**") }
36+
// ====
37+
38+
buildParameters {
39+
pluginId("org.gradlex.internal.gradlex-build-parameters")
40+
bool("ci") {
41+
description = "Whether or not the build is running in a CI environment"
42+
fromEnvironment()
43+
defaultValue = false
44+
}
45+
group("signing") {
46+
// allow to disable signing for locat testing
47+
bool("disable") {
48+
defaultValue = false
49+
}
50+
// key and passphrase need default values because SigningExtension.useInMemoryPgpKeys does not accept providers
51+
description = "Details about artifact signing"
52+
string("key") {
53+
description = "The ID of the PGP key to use for signing artifacts"
54+
fromEnvironment()
55+
defaultValue = "UNSET"
56+
}
57+
string("passphrase") {
58+
description = "The passphrase for the PGP key specified by signing.key"
59+
fromEnvironment()
60+
defaultValue = "UNSET"
61+
}
62+
}
63+
group("pluginPortal") {
64+
// The publish-plugin reads these values directly from System.env. We model them here
65+
// for completeness and documentation purposes.
66+
description = "Credentials for publishing to the plugin portal"
67+
string("key") {
68+
description = "The Plugin portal key for publishing the plugin"
69+
fromEnvironment("GRADLE_PUBLISH_KEY")
70+
}
71+
string("secret") {
72+
description = "The Plugin portal secret for publishing the plugin"
73+
fromEnvironment("GRADLE_PUBLISH_SECRET")
74+
}
75+
}
76+
77+
group("mavenCentral") {
78+
description = "Credentials for publishing to Maven Central"
79+
string("username") {
80+
description = "The Maven Central username for publishing"
81+
fromEnvironment()
82+
}
83+
string("password") {
84+
description = "The Maven Central password for publishing"
85+
fromEnvironment()
86+
}
87+
}
1188
}
1289

1390
pluginPublishConventions {
14-
id("${project.group}.internal.${project.name}")
15-
implementationClass("org.gradlex.conventions.pluginpublish.PluginPublishConventionsPlugin")
16-
displayName("Plugin Publish Conventions Gradle plugin")
17-
description("Conventions for publishing GradleX plugins.")
91+
id("${project.group}.${project.name}")
92+
implementationClass("org.gradlex.conventions.plugin.GradleXPluginConventionsPlugin")
93+
displayName("Conventions for building Gradle plugins")
94+
description("Conventions for building Gradle plugins used by all projects in the GradleX organisation.")
1895
tags("gradlex", "conventions", "publish", "plugins")
1996
gitHub("https://github.com/gradlex-org/plugin-publish-conventions")
2097
developer {
@@ -27,8 +104,9 @@ pluginPublishConventions {
27104
name = "Jendrik Johannes"
28105
29106
}
30-
}
31-
32-
dependencies {
33-
implementation("com.gradle.publish:plugin-publish-plugin:2.0.0")
34-
}
107+
developer {
108+
id = "ljacomet"
109+
name = "Louis Jacomet"
110+
111+
}
112+
}

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
org.gradle.caching=true
2-
org.gradle.parallel=true
3-
systemProp.org.gradle.unsafe.kotlin.assignment=true
2+
org.gradle.configuration-cache=true

gradle/checkstyle/header.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the GradleX team.
2+
* Copyright the GradleX team.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

settings.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
rootProject.name = "plugin-publish-conventions"
2-
31
plugins {
42
id("com.gradle.develocity") version "4.2.2"
53
id("com.gradle.common-custom-user-data-gradle-plugin") version "2.4.0"
64
}
75

6+
rootProject.name = "internal-build-conventions"
7+
88
dependencyResolutionManagement {
99
repositories.gradlePluginPortal()
1010
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright the GradleX team.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradlex.conventions.base;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
import org.gradlex.jvm.dependency.conflict.resolution.JvmDependencyConflictResolutionPlugin;
22+
import org.gradlex.jvm.dependency.conflict.resolution.JvmDependencyConflictsExtension;
23+
import org.jspecify.annotations.NullMarked;
24+
25+
@NullMarked
26+
public abstract class DependencyRulesPlugin implements Plugin<Project> {
27+
@Override
28+
public void apply(Project project) {
29+
var plugins = project.getPlugins();
30+
var extensions = project.getExtensions();
31+
32+
plugins.apply(JvmDependencyConflictResolutionPlugin.class);
33+
34+
var jvmDependencyConflicts = extensions.getByType(JvmDependencyConflictsExtension.class);
35+
var patch = jvmDependencyConflicts.getPatch();
36+
37+
patch.module("com.google.guava:guava", module -> {
38+
module.removeDependency("com.google.code.findbugs:jsr305");
39+
module.removeDependency("com.google.errorprone:error_prone_annotations");
40+
module.removeDependency("com.google.guava:failureaccess");
41+
module.removeDependency("com.google.j2objc:j2objc-annotations");
42+
module.removeDependency("org.checkerframework:checker-qual");
43+
});
44+
patch.module("org.gradle.exemplar:samples-discovery", module -> {
45+
module.removeDependency("org.asciidoctor:asciidoctorj");
46+
});
47+
}
48+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright the GradleX team.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradlex.conventions.base;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
import org.gradle.api.tasks.bundling.Jar;
22+
import org.gradle.api.tasks.testing.Test;
23+
import org.jspecify.annotations.NullMarked;
24+
25+
import java.util.List;
26+
27+
import static org.gradle.api.plugins.JavaBasePlugin.BUILD_DEPENDENTS_TASK_NAME;
28+
import static org.gradle.api.plugins.JavaBasePlugin.BUILD_NEEDED_TASK_NAME;
29+
import static org.gradle.api.plugins.JavaPlugin.CLASSES_TASK_NAME;
30+
import static org.gradle.api.plugins.JavaPlugin.TEST_CLASSES_TASK_NAME;
31+
import static org.gradle.api.plugins.JavaPlugin.TEST_TASK_NAME;
32+
import static org.gradle.language.base.plugins.LifecycleBasePlugin.ASSEMBLE_TASK_NAME;
33+
import static org.gradle.language.base.plugins.LifecycleBasePlugin.BUILD_GROUP;
34+
import static org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP;
35+
36+
@NullMarked
37+
public abstract class LifecycleConventionsPlugin implements Plugin<Project> {
38+
@Override
39+
public void apply(Project project) {
40+
var tasks = project.getTasks();
41+
42+
tasks.register("qualityCheck", task -> {
43+
task.setGroup(VERIFICATION_GROUP);
44+
task.setDescription("Run all spotless and quality checks.");
45+
task.dependsOn(tasks.named(ASSEMBLE_TASK_NAME));
46+
});
47+
tasks.register("qualityGate", task -> {
48+
task.setGroup(BUILD_GROUP);
49+
task.setDescription("Apply spotless rules and run all quality checks.");
50+
task.dependsOn(tasks.named(ASSEMBLE_TASK_NAME));
51+
});
52+
tasks.register("quickCheck", task -> {
53+
task.setGroup(VERIFICATION_GROUP);
54+
task.setDescription("Runs all of qualityCheck and tests only against the current Gradle version.");
55+
task.dependsOn(tasks.named("qualityCheck"));
56+
task.dependsOn(tasks.named(TEST_TASK_NAME));
57+
});
58+
59+
// cleanup 'build' group
60+
var unimportantLifecycleTasks = List.of(
61+
BUILD_DEPENDENTS_TASK_NAME,
62+
BUILD_NEEDED_TASK_NAME,
63+
CLASSES_TASK_NAME,
64+
TEST_CLASSES_TASK_NAME,
65+
"testSamplesClasses"
66+
);
67+
project.afterEvaluate(__ ->
68+
tasks.configureEach(task -> {
69+
if (unimportantLifecycleTasks.contains(task.getName())) {
70+
task.setGroup(null);
71+
}
72+
if (task instanceof Jar) {
73+
task.setGroup(null);
74+
}
75+
if (task instanceof Test) {
76+
task.setGroup(BUILD_GROUP);
77+
}
78+
})
79+
);
80+
}
81+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright the GradleX team.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradlex.conventions.check;
18+
19+
import com.diffplug.gradle.spotless.SpotlessExtension;
20+
import com.diffplug.gradle.spotless.SpotlessPlugin;
21+
import com.diffplug.spotless.LineEnding;
22+
import org.gradle.api.Plugin;
23+
import org.gradle.api.Project;
24+
import org.gradlex.conventions.base.LifecycleConventionsPlugin;
25+
import org.jspecify.annotations.NullMarked;
26+
27+
@NullMarked
28+
public abstract class SpotlessConventionsPlugin implements Plugin<Project> {
29+
30+
@Override
31+
public void apply(Project project) {
32+
var plugins = project.getPlugins();
33+
var extensions = project.getExtensions();
34+
var tasks = project.getTasks();
35+
36+
plugins.apply(SpotlessPlugin.class);
37+
plugins.apply(LifecycleConventionsPlugin.class);
38+
39+
var spotless = extensions.getByType(SpotlessExtension.class);
40+
41+
tasks.named("qualityCheck", task -> task.dependsOn(tasks.named("spotlessCheck")));
42+
tasks.named("qualityGate", task -> task.dependsOn(tasks.named("spotlessApply")));
43+
44+
spotless.setLineEndings(LineEnding.UNIX);
45+
46+
// format the source code
47+
spotless.java(java -> {
48+
java.targetExclude("build/**");
49+
java.palantirJavaFormat();
50+
java.licenseHeader("// SPDX-License-Identifier: Apache-2.0\n", "package|import");
51+
});
52+
// separate 'package-info' formatting due to https://github.com/diffplug/spotless/issues/532
53+
spotless.format("javaPackageInfoFiles", java -> {
54+
java.targetExclude("build");
55+
java.target("src/**/package-info.java");
56+
java.licenseHeader("// SPDX-License-Identifier: Apache-2.0\n", "package|import|@");
57+
});
58+
59+
// format the build itself
60+
spotless.kotlinGradle(gradle ->
61+
gradle.ktfmt().kotlinlangStyle().configure(conf -> conf.setMaxWidth(120)));
62+
}
63+
}

0 commit comments

Comments
 (0)