Skip to content

Commit 03e7731

Browse files
committed
Define more conventions for all GradleX projects
1 parent 6bb395f commit 03e7731

17 files changed

+799
-94
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,30 @@
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**
7+
8+
# TODO: To Discuss
9+
- Rename: 'internal.plugin-publish-conventions' -> 'internal.gradlex-build-conventions'
10+
- Switch to simple SPDX license header?
11+
- Test tags no-cross-version: "org.gradlex.testing.NoCrossVersion" // for vintage?
12+
- Test sample input dirs: 'samples' and 'src/docs/samples'?
13+
- Add checks to enforce setup:
14+
- Build Cache on
15+
- Config Cache on
16+
- Daemon JVM configured to 17
17+
- Dependency Verification on
718

819
# Usage
920

21+
**settings.gradle.kts**
1022
```kotlin
1123
plugins {
12-
id("org.gradlex.internal.plugin-publish-conventions")
24+
id("org.gradlex.internal.gradlex-build-conventions") version "0.7"
1325
}
26+
```
1427

28+
**build.gradle.kts**
29+
```kotlin
1530
pluginPublishConventions {
1631
id("${project.group}.${project.name}")
1732
implementationClass("org.gradlex.buildparameters.BuildParametersPlugin")
@@ -21,6 +36,9 @@ pluginPublishConventions {
2136
gitHub("https://github.com/gradlex-org/build-parameters")
2237
// ...
2338
}
39+
testingConventions {
40+
testGradleVersions("6.8.3", "6.9.4", "7.0.2", "8.0.2", "8.14.3")
41+
}
2442
```
2543

2644
# Disclaimer

build.gradle.kts

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,67 @@
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+
implementation("com.gradle.publish:plugin-publish-plugin:2.0.0")
12+
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.4.0")
13+
implementation("com.gradle:develocity-gradle-plugin:4.2.2")
14+
implementation("org.asciidoctor:asciidoctor-gradle-jvm:4.0.5")
15+
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.4")
16+
implementation("org.gradlex:reproducible-builds:1.1")
17+
}
18+
19+
// ==== the following can be remove once we update the onventions to '0.7'
20+
group = "org.gradlex"
21+
java { toolchain.languageVersion = JavaLanguageVersion.of(17) }
22+
tasks.checkstyleMain { exclude("buildparameters/**") }
23+
buildParameters {
24+
pluginId("gradlexbuild.build-parameters")
25+
bool("ci") {
26+
description.set("Whether or not the build is running in a CI environment")
27+
fromEnvironment()
28+
defaultValue.set(false)
29+
}
30+
group("signing") {
31+
// key and passphrase need default values because SigningExtension.useInMemoryPgpKeys does not accept providers
32+
description.set("Details about artifact signing")
33+
string("key") {
34+
description.set("The ID of the PGP key to use for signing artifacts")
35+
fromEnvironment()
36+
defaultValue.set("UNSET")
37+
}
38+
string("passphrase") {
39+
description.set("The passphrase for the PGP key specified by signing.key")
40+
fromEnvironment()
41+
defaultValue.set("UNSET")
42+
}
43+
}
44+
group("pluginPortal") {
45+
// The publish-plugin reads these values directly from System.env. We model them here
46+
// for completeness and documentation purposes.
47+
description.set("Credentials for publishing to the plugin portal")
48+
string("key") {
49+
description.set("The Plugin portal key for publishing the plugin")
50+
fromEnvironment("GRADLE_PUBLISH_KEY")
51+
}
52+
string("secret") {
53+
description.set("The Plugin portal secret for publishing the plugin")
54+
fromEnvironment("GRADLE_PUBLISH_SECRET")
55+
}
56+
}
1157
}
58+
// ====
1259

1360
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.")
61+
id("${project.group}.internal.gradlex-build-conventions")
62+
implementationClass("org.gradlex.conventions.plugin.GradleXPluginConventionsPlugin")
63+
displayName("Conventions for building Gradle plugins")
64+
description("Conventions for building Gradle plugins used by all projects in the GradleX organisation.")
1865
tags("gradlex", "conventions", "publish", "plugins")
1966
gitHub("https://github.com/gradlex-org/plugin-publish-conventions")
2067
developer {
@@ -27,8 +74,4 @@ pluginPublishConventions {
2774
name = "Jendrik Johannes"
2875
2976
}
30-
}
31-
32-
dependencies {
33-
implementation("com.gradle.publish:plugin-publish-plugin:2.0.0")
34-
}
77+
}

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.
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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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, BUILD_NEEDED_TASK_NAME, CLASSES_TASK_NAME, TEST_CLASSES_TASK_NAME);
62+
project.afterEvaluate(__ ->
63+
tasks.configureEach(task -> {
64+
if (unimportantLifecycleTasks.contains(task.getName())) {
65+
task.setGroup(null);
66+
}
67+
if (task instanceof Jar) {
68+
task.setGroup(null);
69+
}
70+
if (task instanceof Test) {
71+
task.setGroup(BUILD_GROUP);
72+
}
73+
})
74+
);
75+
}
76+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 org.gradle.api.Plugin;
22+
import org.gradle.api.Project;
23+
import org.gradlex.conventions.base.LifecycleConventionsPlugin;
24+
import org.jspecify.annotations.NullMarked;
25+
26+
@NullMarked
27+
public abstract class SpotlessConventionsPlugin implements Plugin<Project> {
28+
29+
@Override
30+
public void apply(Project project) {
31+
var plugins = project.getPlugins();
32+
var extensions = project.getExtensions();
33+
var tasks = project.getTasks();
34+
35+
plugins.apply(SpotlessPlugin.class);
36+
plugins.apply(LifecycleConventionsPlugin.class);
37+
38+
var spotless = extensions.getByType(SpotlessExtension.class);
39+
40+
tasks.named("qualityCheck", task -> task.dependsOn(tasks.named("spotlessCheck")));
41+
tasks.named("qualityGate", task -> task.dependsOn(tasks.named("spotlessApply")));
42+
43+
// format the source code
44+
spotless.java(java -> {
45+
java.palantirJavaFormat();
46+
java.licenseHeader("// SPDX-License-Identifier: Apache-2.0\n", "package|import");
47+
});
48+
spotless.format("javaPackageInfoFiles", java -> {
49+
// add a separate extension due to https://github.com/diffplug/spotless/issues/532
50+
java.target("src/**/package-info.java");
51+
52+
java.licenseHeader("// SPDX-License-Identifier: Apache-2.0\n", "package|import|@");
53+
});
54+
55+
// format the build itself
56+
spotless.kotlinGradle(gradle -> gradle.ktfmt().kotlinlangStyle().configure(conf -> conf.setMaxWidth(120)));
57+
}
58+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.feature;
18+
19+
import org.asciidoctor.gradle.base.log.Severity;
20+
import org.asciidoctor.gradle.jvm.AsciidoctorJPlugin;
21+
import org.asciidoctor.gradle.jvm.AsciidoctorTask;
22+
import org.gradle.api.Plugin;
23+
import org.gradle.api.Project;
24+
import org.gradle.api.plugins.JavaPlugin;
25+
import org.gradle.api.tasks.PathSensitivity;
26+
import org.jspecify.annotations.NullMarked;
27+
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
@NullMarked
32+
public abstract class AsciidoctorConventionsPlugin implements Plugin<Project> {
33+
34+
@Override
35+
public void apply(Project project) {
36+
var plugins = project.getPlugins();
37+
var layout = project.getLayout();
38+
var tasks = project.getTasks();
39+
40+
plugins.apply(JavaPlugin.class);
41+
plugins.apply(AsciidoctorJPlugin.class);
42+
43+
tasks.named("asciidoctor", AsciidoctorTask.class, task -> {
44+
task.notCompatibleWithConfigurationCache(
45+
"https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/564");
46+
task.getInputs().dir("src/docs/samples")
47+
.withPathSensitivity(PathSensitivity.RELATIVE)
48+
.withPropertyName("samples");
49+
50+
task.setFailureLevel(Severity.WARN);
51+
52+
Map<String, Object> attributes = new HashMap<>();
53+
attributes.put("docinfodir", "src/docs/asciidoc");
54+
attributes.put("docinfo", "shared");
55+
attributes.put("imagesdir", "./images");
56+
attributes.put("source-highlighter", "prettify");
57+
attributes.put("tabsize", "4");
58+
attributes.put("toc", "left");
59+
attributes.put("tip-caption", "💡");
60+
attributes.put("note-caption", "ℹ️");
61+
attributes.put("important-caption", "❗");
62+
attributes.put("caution-caption", "🔥");
63+
attributes.put("warning-caption", "⚠️");
64+
attributes.put("sectanchors", true);
65+
attributes.put("idprefix", "");
66+
attributes.put("idseparator", "-");
67+
attributes.put("samples-path", layout.getProjectDirectory().dir("src/docs/samples").getAsFile().toString());
68+
task.setAttributes(attributes);
69+
});
70+
}
71+
}

0 commit comments

Comments
 (0)