Skip to content

Commit

Permalink
update to develocity plugin (#115)
Browse files Browse the repository at this point in the history
* update to develocity plugin

* properly support toolchains
  • Loading branch information
ToppleTheNun authored May 21, 2024
1 parent 8da1c9c commit 4d40e30
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 123 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,7 @@ jobs:
uses: gradle/actions/setup-gradle@aff52e5be96935327d77c5529075184377dc4371 # v3

- name: Perform Build via Gradle
run: ./gradlew build --scan

- name: Publish to Maven Local via Gradle
run: ./gradlew publishToMavenLocal --scan

- name: Upload CodeCov Report
uses: codecov/codecov-action@ab904c41d6ece82784817410c45d8b8c02684457 # v3
with:
files: "**/build/reports/jacoco/**/*.xml"
run: ./gradlew build publishToMavenLocal

- name: Publish Plugin and Create GitHub Release via Gradle
# Release job, only for pushes to the main development branch
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mythicDropsRelease {
The `dev.mythicdrops.gradle.convention.java` plugin will configure the following when applied to any project that also
has the `java` plugin applied:

- Configures the project to compile targeting JDK 16
- Configures the project to compile targeting JDK 17
- Configures the project to pass the `-parameters` javac flag when compiling
- Applies the [`jacoco`](https://docs.gradle.org/current/userguide/jacoco_plugin.html) Gradle plugin
- Configures the `jacoco` plugin to use JaCoCo 0.8.7
Expand All @@ -100,6 +100,15 @@ plugins {
}
```

You can override the JDK version the same way you'd override it in a normal Java project:
```kotlin
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
```

### Kotlin JVM Plugin

The `dev.mythicdrops.gradle.conventions.kotlin.jvm` plugin will configure the following when applied to any project that
Expand Down
9 changes: 5 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ pluginManagement {
plugins {
// See https://jmfayard.github.io/refreshVersions
id("de.fayard.refreshVersions") version "0.60.5"
id("com.gradle.enterprise") version "3.17.4"
id("com.gradle.develocity") version "3.17.4"
}

gradleEnterprise {
develocity {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
publishing.onlyIf { it.buildResult.failures.isNotEmpty() && !System.getenv("CI").isNullOrEmpty() }
termsOfUseUrl = "https://gradle.com/terms-of-service"
termsOfUseAgree = "yes"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package dev.mythicdrops.gradle.conventions

import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.jacoco.plugins.JacocoPlugin
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.tasks.JacocoReport

val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17
const val DEFAULT_JAVA_VERSION = 17

/**
* Plugin that configures Java for JDK 17 and enables JaCoCo.
*/
open class MythicDropsJavaPlugin : DependentPlugin("Java", "java") {
override fun configureProject(target: Project) {
val javaExtension =
target.extensions.create<MythicDropsJavaExtension>("mythicDropsJava").apply {
// default to Java 17
javaVersion.convention(DEFAULT_JAVA_VERSION)
}

target.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(javaExtension.javaVersion.get().majorVersion))
languageVersion.convention(JavaLanguageVersion.of(DEFAULT_JAVA_VERSION))
}
}

Expand Down
184 changes: 101 additions & 83 deletions src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,126 @@ package dev.mythicdrops.gradle.spigot
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Property
import org.gradle.api.services.ServiceReference
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.TaskAction
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.kotlin.dsl.getByType
import org.gradle.process.ExecOperations
import java.io.File
import java.nio.file.Paths
import javax.inject.Inject

abstract class RunSpigotBuildToolsTask
@Inject
constructor(
private val execOperations: ExecOperations,
private val fileSystemOperations: FileSystemOperations,
) : DefaultTask() {
@get:ServiceReference(SyncTaskBuildService.NAME)
abstract val syncTask: Property<SyncTaskBuildService>
abstract class RunSpigotBuildToolsTask : DefaultTask() {
@get:ServiceReference(SyncTaskBuildService.NAME)

Check warning on line 22 in src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt

View workflow job for this annotation

GitHub Actions / qodana

Unstable API Usage

'org.gradle.api.services.ServiceReference' is marked unstable with @Incubating
abstract val syncTask: Property<SyncTaskBuildService>

@get:InputFile
abstract val buildToolsLocation: RegularFileProperty
@get:InputFile
abstract val buildToolsLocation: RegularFileProperty

@get:Input
abstract val includeRemapped: Property<Boolean>
@get:Input
abstract val includeRemapped: Property<Boolean>

@get:Input
abstract val version: Property<String>
@get:Input
abstract val version: Property<String>

init {
description = "Runs Spigot BuildTools.jar for a specific Minecraft version"
group = "spigot"
@get:Nested
abstract val launcher: Property<JavaLauncher>

@get:Inject
abstract val execOperations: ExecOperations

@get:Inject
abstract val fileSystemOperations: FileSystemOperations

@get:Inject
abstract val javaToolchainService: JavaToolchainService

init {
description = "Runs Spigot BuildTools.jar for a specific Minecraft version"
group = "spigot"

val toolchain = project.extensions.getByType<JavaPluginExtension>().toolchain
val defaultLauncher = javaToolchainService.launcherFor(toolchain)

Check warning on line 51 in src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt

View workflow job for this annotation

GitHub Actions / qodana

Leaking 'this' in constructor

Accessing non-final property javaToolchainService in constructor
launcher.convention(defaultLauncher)

Check warning on line 52 in src/main/kotlin/dev/mythicdrops/gradle/spigot/RunSpigotBuildToolsTask.kt

View workflow job for this annotation

GitHub Actions / qodana

Leaking 'this' in constructor

Accessing non-final property launcher in constructor
}

@TaskAction
fun runSpigotBuildTools() {
val version = version.getOrElse("")
if (version.isBlank()) {
logger.lifecycle("Not running Spigot build tools as the version is blank")
return
}

@TaskAction
fun runSpigotBuildTools() {
val version = version.getOrElse("")
if (version.isBlank()) {
logger.lifecycle("Not running Spigot build tools as the version is blank")
return
}

val mavenLocalDirectory = Paths.get(project.repositories.mavenLocal().url).toFile()
if (!mavenLocalDirectory.exists()) {
logger.lifecycle("Creating Maven Local repository at ${mavenLocalDirectory.absolutePath}")
mavenLocalDirectory.mkdirs()
}

normalVersion(mavenLocalDirectory, version)
if (includeRemapped.getOrElse(false)) {
remappedVersion(mavenLocalDirectory, version)
}
val mavenLocalDirectory = Paths.get(project.repositories.mavenLocal().url).toFile()
if (!mavenLocalDirectory.exists()) {
logger.lifecycle("Creating Maven Local repository at ${mavenLocalDirectory.absolutePath}")
mavenLocalDirectory.mkdirs()
}

private fun normalVersion(
mavenLocalDirectory: File,
version: String,
) {
val versionJar =
mavenLocalDirectory.resolve(
"org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT.jar",
)
if (versionJar.exists()) {
logger.lifecycle("Skipping $version as Spigot JAR is found at ${versionJar.absolutePath}")
return
}
val jar = buildToolsLocation.get().asFile
val versionDir = jar.parentFile.resolve(version)
fileSystemOperations.copy {
from(jar)
into(versionDir)
}
execOperations.javaexec {
args(listOf("--rev", version))
workingDir = versionDir.absoluteFile
jvmArgs = listOf("-Xmx1024M")
classpath(buildToolsLocation)
}
normalVersion(mavenLocalDirectory, version)
if (includeRemapped.getOrElse(false)) {
remappedVersion(mavenLocalDirectory, version)
}
}

private fun remappedVersion(
mavenLocalDirectory: File,
version: String,
) {
val versionJar =
mavenLocalDirectory.resolve(
"org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT-remapped-mojang.jar",
)
if (versionJar.exists()) {
logger.lifecycle("Skipping $version as Spigot remapped JAR is found at ${versionJar.absolutePath}")
return
}
val jar = buildToolsLocation.get().asFile
val versionDir = jar.parentFile.resolve(version)
fileSystemOperations.copy {
from(jar)
into(versionDir)
}
execOperations.javaexec {
args(listOf("--rev", version, "--remapped"))
workingDir = versionDir.absoluteFile
jvmArgs = listOf("-Xmx1024M")
classpath(buildToolsLocation)
}
private fun normalVersion(
mavenLocalDirectory: File,
version: String,
) {
val versionJar =
mavenLocalDirectory.resolve(
"org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT.jar",
)
if (versionJar.exists()) {
logger.lifecycle("Skipping $version as Spigot JAR is found at ${versionJar.absolutePath}")
return
}
val jar = buildToolsLocation.get().asFile
val versionDir = jar.parentFile.resolve(version)
fileSystemOperations.copy {
from(jar)
into(versionDir)
}
execOperations.javaexec {
args(listOf("--rev", version))
workingDir = versionDir.absoluteFile
jvmArgs = listOf("-Xmx1024M")
classpath(buildToolsLocation)
executable(launcher.get().executablePath)
}
}

private fun remappedVersion(
mavenLocalDirectory: File,
version: String,
) {
val versionJar =
mavenLocalDirectory.resolve(
"org/spigotmc/spigot/$version-R0.1-SNAPSHOT/spigot-$version-R0.1-SNAPSHOT-remapped-mojang.jar",
)
if (versionJar.exists()) {
logger.lifecycle("Skipping $version as Spigot remapped JAR is found at ${versionJar.absolutePath}")
return
}
val jar = buildToolsLocation.get().asFile
val versionDir = jar.parentFile.resolve(version)
fileSystemOperations.copy {
from(jar)
into(versionDir)
}
execOperations.javaexec {
args(listOf("--rev", version, "--remapped"))
workingDir = versionDir.absoluteFile
jvmArgs = listOf("-Xmx1024M")
classpath(buildToolsLocation)
executable(launcher.get().executablePath)
}
}
}
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=7.2.*
version=8.0.*
3 changes: 1 addition & 2 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ plugin.io.gitlab.arturbosch.detekt=1.23.6

plugin.org.jetbrains.dokka=1.9.20

plugin.org.jlleitschuh.gradle.ktlint=12.1.0
## # available=12.1.1
plugin.org.jlleitschuh.gradle.ktlint=12.1.1

plugin.org.shipkit.shipkit-auto-version=2.0.7

Expand Down

0 comments on commit 4d40e30

Please sign in to comment.