Skip to content
Merged
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
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
[![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)
[![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)

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

# Usage

**settings.gradle.kts**
```kotlin
plugins {
id("org.gradlex.internal.plugin-publish-conventions")
id("org.gradlex.internal-build-conventions") version "0.7"
}
```

pluginPublishConventions {
id("${project.group}.${project.name}")
implementationClass("org.gradlex.buildparameters.BuildParametersPlugin")
displayName("Build Parameters Gradle Plugin")
description("Compile-safe access to parameters supplied to a Gradle build.")
tags("gradlex", "parameters", "build parameters")
**build.gradle.kts**
```kotlin
publishingConventions {
pluginPortal("${project.group}.${project.name}") {
implementationClass("org.gradlex.buildparameters.BuildParametersPlugin")
displayName("Build Parameters Gradle Plugin")
description("Compile-safe access to parameters supplied to a Gradle build.")
tags("gradlex", "parameters", "build parameters")
}
gitHub("https://github.com/gradlex-org/build-parameters")
// ...
}
testingConventions {
testGradleVersions("6.8.3", "6.9.4", "7.0.2", "8.0.2", "8.14.3")
}
```

# Disclaimer
Expand Down
102 changes: 90 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,97 @@
plugins {
id("java-gradle-plugin")
id("org.gradlex.build-parameters") version "1.4.4"
id("org.gradlex.internal.plugin-publish-conventions") version "0.6"
}

group = "org.gradlex"
version = "0.7"

java {
toolchain.languageVersion = JavaLanguageVersion.of(11)
dependencies {
implementation("com.diffplug.spotless:spotless-plugin-gradle:8.0.0") {
// Exclude transitive dependencies of JGit as we do not need git functionality.
// We can't exclude JGit itself as types are referenced in SpotlessTask.class.
exclude("com.googlecode.javaewah", "JavaEWAH")
exclude("commons-codec", "commons-codec")
exclude("org.slf4j", "slf4j-api")
}
implementation("com.gradle.publish:plugin-publish-plugin:2.0.0")
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.4.0")
implementation("com.gradle:develocity-gradle-plugin:4.2.2")
implementation("com.gradleup.nmcp:nmcp:1.2.0")
implementation("org.asciidoctor:asciidoctor-gradle-jvm:4.0.5")
implementation("org.gradlex:jvm-dependency-conflict-resolution:2.4")
implementation("org.gradlex:reproducible-builds:1.1")
}

dependencies.constraints {
implementation("org.jetbrains:annotations:13.0!!") {
because("This version is enforced by Gradle through the Kotlin plugin")
}
}

// ==== the following can be remove once we update the onventions to '0.7'
group = "org.gradlex"
java { toolchain.languageVersion = JavaLanguageVersion.of(17) }
tasks.checkstyleMain { exclude("buildparameters/**") }
// ====

buildParameters {
pluginId("org.gradlex.internal.gradlex-build-parameters")
bool("ci") {
description = "Whether or not the build is running in a CI environment"
fromEnvironment()
defaultValue = false
}
group("signing") {
// allow to disable signing for locat testing
bool("disable") {
defaultValue = false
}
// key and passphrase need default values because SigningExtension.useInMemoryPgpKeys does not accept providers
description = "Details about artifact signing"
string("key") {
description = "The ID of the PGP key to use for signing artifacts"
fromEnvironment()
defaultValue = "UNSET"
}
string("passphrase") {
description = "The passphrase for the PGP key specified by signing.key"
fromEnvironment()
defaultValue = "UNSET"
}
}
group("pluginPortal") {
// The publish-plugin reads these values directly from System.env. We model them here
// for completeness and documentation purposes.
description = "Credentials for publishing to the plugin portal"
string("key") {
description = "The Plugin portal key for publishing the plugin"
fromEnvironment("GRADLE_PUBLISH_KEY")
}
string("secret") {
description = "The Plugin portal secret for publishing the plugin"
fromEnvironment("GRADLE_PUBLISH_SECRET")
}
}

group("mavenCentral") {
description = "Credentials for publishing to Maven Central"
string("username") {
description = "The Maven Central username for publishing"
fromEnvironment()
}
string("password") {
description = "The Maven Central password for publishing"
fromEnvironment()
}
}
}

pluginPublishConventions {
id("${project.group}.internal.${project.name}")
implementationClass("org.gradlex.conventions.pluginpublish.PluginPublishConventionsPlugin")
displayName("Plugin Publish Conventions Gradle plugin")
description("Conventions for publishing GradleX plugins.")
id("${project.group}.${project.name}")
implementationClass("org.gradlex.conventions.plugin.GradleXPluginConventionsPlugin")
displayName("Conventions for building Gradle plugins")
description("Conventions for building Gradle plugins used by all projects in the GradleX organisation.")
tags("gradlex", "conventions", "publish", "plugins")
gitHub("https://github.com/gradlex-org/plugin-publish-conventions")
developer {
Expand All @@ -27,8 +104,9 @@ pluginPublishConventions {
name = "Jendrik Johannes"
email = "[email protected]"
}
}

dependencies {
implementation("com.gradle.publish:plugin-publish-plugin:2.0.0")
}
developer {
id = "ljacomet"
name = "Louis Jacomet"
email = "[email protected]"
}
}
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
org.gradle.caching=true
org.gradle.parallel=true
systemProp.org.gradle.unsafe.kotlin.assignment=true
org.gradle.configuration-cache=true
2 changes: 1 addition & 1 deletion gradle/checkstyle/header.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 the GradleX team.
* Copyright the GradleX team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
rootProject.name = "plugin-publish-conventions"

plugins {
id("com.gradle.develocity") version "4.2.2"
id("com.gradle.common-custom-user-data-gradle-plugin") version "2.4.0"
}

rootProject.name = "internal-build-conventions"

dependencyResolutionManagement {
repositories.gradlePluginPortal()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright the GradleX team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradlex.conventions.base;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradlex.jvm.dependency.conflict.resolution.JvmDependencyConflictResolutionPlugin;
import org.gradlex.jvm.dependency.conflict.resolution.JvmDependencyConflictsExtension;
import org.jspecify.annotations.NullMarked;

@NullMarked
public abstract class DependencyRulesPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
var plugins = project.getPlugins();
var extensions = project.getExtensions();

plugins.apply(JvmDependencyConflictResolutionPlugin.class);

var jvmDependencyConflicts = extensions.getByType(JvmDependencyConflictsExtension.class);
var patch = jvmDependencyConflicts.getPatch();

patch.module("com.google.guava:guava", module -> {
module.removeDependency("com.google.code.findbugs:jsr305");
module.removeDependency("com.google.errorprone:error_prone_annotations");
module.removeDependency("com.google.guava:failureaccess");
module.removeDependency("com.google.j2objc:j2objc-annotations");
module.removeDependency("org.checkerframework:checker-qual");
});
patch.module("org.gradle.exemplar:samples-discovery", module -> {
module.removeDependency("org.asciidoctor:asciidoctorj");
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright the GradleX team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradlex.conventions.base;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.api.tasks.testing.Test;
import org.jspecify.annotations.NullMarked;

import java.util.List;

import static org.gradle.api.plugins.JavaBasePlugin.BUILD_DEPENDENTS_TASK_NAME;
import static org.gradle.api.plugins.JavaBasePlugin.BUILD_NEEDED_TASK_NAME;
import static org.gradle.api.plugins.JavaPlugin.CLASSES_TASK_NAME;
import static org.gradle.api.plugins.JavaPlugin.TEST_CLASSES_TASK_NAME;
import static org.gradle.api.plugins.JavaPlugin.TEST_TASK_NAME;
import static org.gradle.language.base.plugins.LifecycleBasePlugin.ASSEMBLE_TASK_NAME;
import static org.gradle.language.base.plugins.LifecycleBasePlugin.BUILD_GROUP;
import static org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP;

@NullMarked
public abstract class LifecycleConventionsPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
var tasks = project.getTasks();

tasks.register("qualityCheck", task -> {
task.setGroup(VERIFICATION_GROUP);
task.setDescription("Run all spotless and quality checks.");
task.dependsOn(tasks.named(ASSEMBLE_TASK_NAME));
});
tasks.register("qualityGate", task -> {
task.setGroup(BUILD_GROUP);
task.setDescription("Apply spotless rules and run all quality checks.");
task.dependsOn(tasks.named(ASSEMBLE_TASK_NAME));
});
tasks.register("quickCheck", task -> {
task.setGroup(VERIFICATION_GROUP);
task.setDescription("Runs all of qualityCheck and tests only against the current Gradle version.");
task.dependsOn(tasks.named("qualityCheck"));
task.dependsOn(tasks.named(TEST_TASK_NAME));
});

// cleanup 'build' group
var unimportantLifecycleTasks = List.of(
BUILD_DEPENDENTS_TASK_NAME,
BUILD_NEEDED_TASK_NAME,
CLASSES_TASK_NAME,
TEST_CLASSES_TASK_NAME,
"testSamplesClasses"
);
project.afterEvaluate(__ ->
tasks.configureEach(task -> {
if (unimportantLifecycleTasks.contains(task.getName())) {
task.setGroup(null);
}
if (task instanceof Jar) {
task.setGroup(null);
}
if (task instanceof Test) {
task.setGroup(BUILD_GROUP);
}
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright the GradleX team.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradlex.conventions.check;

import com.diffplug.gradle.spotless.SpotlessExtension;
import com.diffplug.gradle.spotless.SpotlessPlugin;
import com.diffplug.spotless.LineEnding;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradlex.conventions.base.LifecycleConventionsPlugin;
import org.jspecify.annotations.NullMarked;

@NullMarked
public abstract class SpotlessConventionsPlugin implements Plugin<Project> {

@Override
public void apply(Project project) {
var plugins = project.getPlugins();
var extensions = project.getExtensions();
var tasks = project.getTasks();

plugins.apply(SpotlessPlugin.class);
plugins.apply(LifecycleConventionsPlugin.class);

var spotless = extensions.getByType(SpotlessExtension.class);

tasks.named("qualityCheck", task -> task.dependsOn(tasks.named("spotlessCheck")));
tasks.named("qualityGate", task -> task.dependsOn(tasks.named("spotlessApply")));

spotless.setLineEndings(LineEnding.UNIX);

// format the source code
spotless.java(java -> {
java.targetExclude("build/**");
java.palantirJavaFormat();
java.licenseHeader("// SPDX-License-Identifier: Apache-2.0\n", "package|import");
});
// separate 'package-info' formatting due to https://github.com/diffplug/spotless/issues/532
spotless.format("javaPackageInfoFiles", java -> {
java.targetExclude("build");
java.target("src/**/package-info.java");
java.licenseHeader("// SPDX-License-Identifier: Apache-2.0\n", "package|import|@");
});

// format the build itself
spotless.kotlinGradle(gradle ->
gradle.ktfmt().kotlinlangStyle().configure(conf -> conf.setMaxWidth(120)));
}
}
Loading