Skip to content

Commit

Permalink
fix extension creation (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ToppleTheNun authored Dec 10, 2021
1 parent 125b0b4 commit 2dcd7fa
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-auto-version#fetch-depth-on-ci
fetch-depth: "0" # https://github.com/shipkit/shipkit-auto-version#fetch-depth-on-ci
- name: Gradle wrapper validation
uses: gradle/[email protected]

Expand All @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-auto-version#fetch-depth-on-ci
fetch-depth: "0" # https://github.com/shipkit/shipkit-auto-version#fetch-depth-on-ci
- name: Run build
run: .\gradlew.bat build --continue

Expand All @@ -41,7 +41,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-auto-version#fetch-depth-on-ci
fetch-depth: "0" # https://github.com/shipkit/shipkit-auto-version#fetch-depth-on-ci
- name: Make gradlew Executable
run: chmod +x ./gradlew
- name: Run build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# More info at https://megalinter.github.io
name: MegaLinter

# cSpell:words megalinter stefanzweifel

on:
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to master
push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
Expand Down
4 changes: 2 additions & 2 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DEFAULT_BRANCH: main # Usually master or main
# ENABLE: # If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default
# ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
# DISABLE:
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
# - SPELL # Uncomment to disable checks of spelling mistakes
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
# - SPELL # Uncomment to disable checks of spelling mistakes
SHOW_ELAPSED_TIME: true
FILEIO_REPORTER: false
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The `dev.mythicdrops.gradle.project.base` plugin will configure the following wh

- Applies the [`nebula.project`](https://github.com/nebula-plugins/nebula-project-plugin) Gradle plugin
- Applies the [`com.adarshr.test-logger`](https://github.com/radarsh/gradle-test-logger-plugin) Gradle plugin
- Configures the `com.adarshr.test-logger` plugin to use
- Configures the `com.adarshr.test-logger` plugin to use
the [Mocha theme](https://github.com/radarsh/gradle-test-logger-plugin#mocha-theme)
- Configures all test tasks to use JUnit Jupiter

Expand Down Expand Up @@ -87,7 +87,7 @@ has the `java` plugin applied:
- Configures the project to compile targeting JDK 16
- 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
- Configures the `jacoco` plugin to use JaCoCo 0.8.7
- Configures tests to be finalized by running a JaCoCo code coverage report

#### Usage
Expand All @@ -109,7 +109,7 @@ also has the `org.jetbrains.kotlin.jvm` plugin applied:
- Configures the project to pass the `-parameters` javac flag when compiling
- Applies the [`detekt`](https://detekt.github.io/detekt/gradle.html) Gradle plugin
- Applies the [`ktlint`](https://github.com/JLLeitschuh/ktlint-gradle) Gradle plugin
- Configures the `ktlint` plugin to use KTLint 0.43.0
- Configures the `ktlint` plugin to use KTLint 0.43.0
- Applies the [`dokka`](https://github.com/Kotlin/dokka) Gradle plugin
- Configures Javadoc JARs to include dokka output

Expand Down
4 changes: 1 addition & 3 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"config:base"
]
"extends": ["config:base"]
}
9 changes: 9 additions & 0 deletions src/main/kotlin/dev/mythicdrops/gradle/ExtensionContainers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.mythicdrops.gradle

import dev.mythicdrops.gradle.conventions.MythicDropsJavaExtension
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.findByType

fun ExtensionContainer.findOrCreateMythicDropsJavaExtension(): MythicDropsJavaExtension =
findByType() ?: create("mythicDropsJava")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.mythicdrops.gradle.conventions

import org.gradle.api.JavaVersion

/**
* Configuration for selecting which version of Java to compile for.
*
* @property javaVersion Version of Java to compile for (e.g., Java 16/17)
*/
open class MythicDropsJavaExtension {
var javaVersion: String = JavaVersion.VERSION_16.majorVersion
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.mythicdrops.gradle.conventions

import dev.mythicdrops.gradle.findOrCreateMythicDropsJavaExtension
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.compile.JavaCompile
Expand All @@ -15,23 +16,13 @@ import org.gradle.testing.jacoco.tasks.JacocoReport
* Plugin that configures Java for JDK 16 and enables JaCoCo.
*/
open class MythicDropsJavaPlugin : DependentPlugin("Java", "java") {
companion object {
/**
* Version of Java supported by the plugin.
*/
const val JAVA_VERSION = 16

/**
* Version of Java supported by the plugin.
*/
val javaLanguageVersion = JavaLanguageVersion.of(JAVA_VERSION)
}

override fun configureProject(target: Project) {
val javaExtension = target.extensions.findOrCreateMythicDropsJavaExtension()

// target JDK 16
target.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(javaLanguageVersion)
languageVersion.set(JavaLanguageVersion.of(javaExtension.javaVersion))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.mythicdrops.gradle.conventions

import dev.mythicdrops.gradle.findOrCreateMythicDropsJavaExtension
import io.gitlab.arturbosch.detekt.DetektPlugin
import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Jar
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainSpec
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByName
Expand All @@ -19,6 +21,8 @@ import org.jlleitschuh.gradle.ktlint.KtlintPlugin
*/
open class MythicDropsKotlinJvmPlugin : DependentPlugin("Kotlin JVM", "org.jetbrains.kotlin.jvm") {
override fun configureProject(target: Project) {
val javaExtension = target.extensions.findOrCreateMythicDropsJavaExtension()

// apply plugins
target.pluginManager.apply(DetektPlugin::class.java)
target.pluginManager.apply(DokkaPlugin::class.java)
Expand All @@ -27,7 +31,7 @@ open class MythicDropsKotlinJvmPlugin : DependentPlugin("Kotlin JVM", "org.jetbr
// configure kotlin to use JDK 16
target.configure<KotlinJvmProjectExtension> {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(MythicDropsJavaPlugin.javaLanguageVersion)
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(javaExtension.javaVersion))
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.1.*
version=2.2.*

0 comments on commit 2dcd7fa

Please sign in to comment.