Skip to content

Commit

Permalink
Merge pull request #40 from bjhargrave/gradle-8.1
Browse files Browse the repository at this point in the history
gradle 8.1: Update code and build for Gradle 8.1 and Java 20
  • Loading branch information
bjhargrave authored Jun 27, 2023
2 parents 8edf010 + f1f1d09 commit d5cf561
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cibuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- '8'
- '11'
- '17'
- '19'
- '20'
name: Build JDK${{ matrix.java }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ tasks.named("jar") {
This plugin requires at least Gradle 6.1 for Java 8 to Java 15,
at least Gradle 7.0 for Java 16,
at least Gradle 7.3 for Java 17,
and at least Gradle 7.5 for Java 18.
at least Gradle 7.5 for Java 18,
at least Gradle 7.6 for Java 19,
and at least Gradle 8.1 for Java 20.


[1]: https://maven.apache.org/shared/maven-archiver/index.html
40 changes: 25 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import java.util.*

plugins {
Expand Down Expand Up @@ -26,7 +29,7 @@ localrepo?.let {
while (rootGradle.parent != null) {
rootGradle = rootGradle.parent!!
}
val maven_repo_local by extra(rootGradle.startParameter.currentDir.resolve(it).normalize().absolutePath)
extra.set("maven_repo_local", rootGradle.startParameter.currentDir.resolve(it).normalize().absolutePath)
}
val maven_repo_local: String? by extra

Expand All @@ -48,13 +51,16 @@ sourceSets {
}

configurations {
val dslCompileOnly by existing {
val dslCompileOnly by existing
dslCompileOnly {
extendsFrom(compileOnly.get())
}
val dslImplementation by existing {
val dslImplementation by existing
dslImplementation {
extendsFrom(implementation.get())
}
val dslRuntimeOnly by existing {
val dslRuntimeOnly by existing
dslRuntimeOnly {
extendsFrom(runtimeOnly.get())
}
}
Expand All @@ -67,24 +73,19 @@ dependencies {

// Gradle plugin descriptions
gradlePlugin {
website.set("https://github.com/bjhargrave/add-maven-descriptor")
vcsUrl.set("https://github.com/bjhargrave/add-maven-descriptor.git")
plugins {
create("AddMavenDescriptor") {
id = "dev.hargrave.addmavendescriptor"
implementationClass = "dev.hargrave.gradle.addmavendescriptor.AddMavenDescriptorPlugin"
displayName = "Add Maven Descriptor Plugin"
description = "Gradle Plugin to add Maven descriptor information to built jars."
tags.set(listOf("maven", "pom"))
}
}
}

// Gradle plugin bundle description
pluginBundle {
website = "https://github.com/bjhargrave/add-maven-descriptor"
vcsUrl = "https://github.com/bjhargrave/add-maven-descriptor.git"
description = "Gradle Plugin to add Maven descriptor information to built jars."
tags = listOf("maven", "pom")
}

publishing {
publications {
// Main plugin publication
Expand All @@ -94,10 +95,12 @@ publishing {
description.set("Add Maven Descriptor")
}
val publication = this
tasks.register<WriteProperties>("generatePomPropertiesFor${publication.name.capitalize()}Publication") {
tasks.register<WriteProperties>("generatePomPropertiesFor${publication.name.replaceFirstChar {
it.titlecase(Locale.ROOT)
}}Publication") {
description = "Generates the Maven pom.properties file for publication '${publication.name}'."
group = PublishingPlugin.PUBLISH_TASK_GROUP
setOutputFile(layout.buildDirectory.file("publications/${publication.name}/pom-default.properties"))
getDestinationFile().value(layout.buildDirectory.file("publications/${publication.name}/pom-default.properties"))
property("groupId", provider { publication.groupId })
property("artifactId", provider { publication.artifactId })
property("version", provider { publication.version })
Expand Down Expand Up @@ -142,6 +145,13 @@ publishing {
}
}

// Use same jvm target for kotlin code as for java code
tasks.withType<KotlinCompilationTask<KotlinJvmCompilerOptions>>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(java.targetCompatibility.toString()))
}
}

// Disable gradle module metadata
tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
Expand Down Expand Up @@ -209,7 +219,7 @@ tasks.test {
}
val testresourcesSource = layout.projectDirectory.dir("testresources")
inputs.files(testresourcesSource).withPathSensitivity(PathSensitivity.RELATIVE).withPropertyName("testresources")
systemProperty("org.gradle.warning.mode", gradle.startParameter.warningMode.name.toLowerCase(Locale.ROOT))
systemProperty("org.gradle.warning.mode", gradle.startParameter.warningMode.name.lowercase(Locale.ROOT))
maven_repo_local?.let {
systemProperty("maven.repo.local", it)
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
11 changes: 6 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -144,15 +141,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package dev.hargrave.gradle.addmavendescriptor;

import java.util.SortedSet;
import java.util.function.BiConsumer;

import org.gradle.api.NamedDomainObjectSet;
import org.gradle.api.Project;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RegularFile;
import org.gradle.api.plugins.PluginManager;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.plugins.PublishingPlugin;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.WriteProperties;
import org.gradle.util.GradleVersion;

/**
* Plugin extension to specify the MavenPublication name to
Expand Down Expand Up @@ -108,14 +112,19 @@ private void configureProject(Project project) {
ProjectLayout layout = project.getLayout();
ProviderFactory providers = project.getProviders();

@SuppressWarnings("deprecation")
BiConsumer<WriteProperties, Provider<RegularFile>> setDestinationFile = isGradleCompatible("8.1") ? //
(task, destinationFile) -> task.getDestinationFile()
.value(destinationFile) : //
(task, destinationFile) -> task.setOutputFile(destinationFile);
// Register generatePomProperties task for each MavenPublication
publications().configureEach(publication -> {
String pomPropertiesTaskName = "generatePomPropertiesFor" + capitalize(publication.getName()) + "Publication";
tasks.register(pomPropertiesTaskName, WriteProperties.class, task -> {
String publicationName = publication.getName();
task.setDescription("Generates the Maven pom.properties file for publication '" + publicationName + "'.");
task.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
task.setOutputFile(layout.getBuildDirectory()
setDestinationFile.accept(task, layout.getBuildDirectory()
.file("publications/" + publicationName + "/pom-default.properties"));
task.property("groupId", providers.provider(publication::getGroupId));
task.property("artifactId", providers.provider(publication::getArtifactId));
Expand Down Expand Up @@ -148,4 +157,15 @@ static String capitalize(String string) {
}
return new String(codePoints, 0, count);
}

/**
* Return whether the current Gradle is at least the specified version.
*
* @param requestedVersion The requested Gradle version.
* @return Whether the current Gradle is at least the specified version.
*/
static boolean isGradleCompatible(String requestedVersion) {
return GradleVersion.current()
.compareTo(GradleVersion.version(requestedVersion)) >= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ class TestAddMavenDescriptorPlugin extends Specification {

when:
UTF8Properties props = new UTF8Properties()
def result = TestHelper.getGradleRunner()
def result = TestHelper.getGradleRunner("7.6")
.withProjectDir(testProjectDir)
.withArguments("--parallel", "--stacktrace", "--debug", "build")
.withPluginClasspath()
Expand Down Expand Up @@ -842,7 +842,7 @@ class TestAddMavenDescriptorPlugin extends Specification {
jartask_jar.close()

when:
result = TestHelper.getGradleRunner()
result = TestHelper.getGradleRunner("7.6")
.withProjectDir(testProjectDir)
.withArguments("--parallel", "--stacktrace", "--debug", "build")
.withPluginClasspath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class TestHelper {
}

private static String gradleVersion() {
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_20)) {
return "8.1"
}
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_19)) {
return "7.6"
}
Expand Down
13 changes: 4 additions & 9 deletions testresources/plugin14/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("dev.hargrave.addmavendescriptor")
groovy
`kotlin-dsl`
id("com.gradle.plugin-publish") version "1.0.0"
id("com.gradle.plugin-publish") version "1.2.0"
}

group = "test.addmavendescriptor.gradle"
Expand All @@ -25,24 +25,19 @@ dependencies {

// Gradle plugin description
gradlePlugin {
website.set("https://github.com/bjhargrave/add-maven-descriptor")
vcsUrl.set("https://github.com/bjhargrave/add-maven-descriptor.git")
plugins {
create("Test") {
id = "test.addmavendescriptor.gradle"
implementationClass = "doubler.impl.DoublerImpl"
displayName = "Test Gradle Plugin"
description = "Gradle Plugin for a test."
tags.set(listOf("gradle", "maven"))
}
}
}

// Gradle plugin bundle description
pluginBundle {
website = "https://github.com/bjhargrave/add-maven-descriptor"
vcsUrl = "https://github.com/bjhargrave/add-maven-descriptor.git"
description = "Gradle Plugin for a test."
tags = listOf("gradle", "maven")
}

publishing {
publications {
create<MavenPublication>("pluginMaven") {
Expand Down

0 comments on commit d5cf561

Please sign in to comment.