11import  com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask 
2- import  com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation 
32import  com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 
43import  org.gradle.api.tasks.testing.logging.TestExceptionFormat 
54import  org.gradle.api.tasks.testing.logging.TestLogEvent 
65import  org.jetbrains.kotlin.gradle.dsl.JvmTarget 
6+ import  org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension 
77import  org.jetbrains.kotlin.gradle.dsl.KotlinVersion 
88import  org.jetbrains.kotlin.gradle.tasks.KotlinCompile 
99import  org.jetbrains.kotlin.util.prefixIfNot 
@@ -13,7 +13,7 @@ plugins {
1313    `kotlin- dsl`
1414    `maven- publish`
1515    id(" org.jlleitschuh.gradle.ktlint" 
16-     id(" com.github.johnrengelman .shadow" 
16+     id(" com.gradleup .shadow" 
1717    id(" com.github.breadmoirai.github-release" 
1818    id(" com.netflix.nebula.release" 
1919}
@@ -27,6 +27,8 @@ repositories {
2727}
2828
2929java {
30+     withJavadocJar()
31+     withSourcesJar()
3032    toolchain {
3133        languageVersion.set(JavaLanguageVersion .of(8 ))
3234    }
@@ -38,30 +40,12 @@ ktlint {
3840
3941tasks.withType<KotlinCompile > {
4042    compilerOptions {
41-         languageVersion.set(KotlinVersion .KOTLIN_1_7 )
42-         apiVersion.set(KotlinVersion .KOTLIN_1_7 )
43+         languageVersion.set(KotlinVersion .KOTLIN_1_8 )
44+         apiVersion.set(KotlinVersion .KOTLIN_1_8 )
4345        jvmTarget.set(JvmTarget .JVM_1_8 )
4446    }
4547}
4648
47- tasks.withType<PluginUnderTestMetadata >().configureEach {
48-     pluginClasspath.from(configurations.compileOnly)
49- }
50- 
51- /* *
52-  * Special configuration to be included in resulting shadowed jar, but not added to the generated pom and gradle 
53-  * metadata files. 
54-  */  
55- val  shadowImplementation by configurations.creating
56- configurations {
57-     val  compileOnly by getting {
58-         extendsFrom(shadowImplementation)
59-         isCanBeResolved =  true 
60-     }
61- }
62- configurations[" compileOnly" 
63- configurations[" testImplementation" 
64- 
6549dependencies {
6650    compileOnly(" com.pinterest.ktlint:ktlint-cli-reporter-core:1.0.0" 
6751    compileOnly(" com.pinterest.ktlint:ktlint-rule-engine:1.0.0" 
@@ -70,23 +54,70 @@ dependencies {
7054    compileOnly(libs.kotlin.gradle.plugin)
7155    compileOnly(libs.android.gradle.plugin)
7256    compileOnly(kotlin(" stdlib-jdk8" 
57+     implementation(libs.semver)
58+     implementation(libs.jgit)
59+     implementation(libs.commons.io)
7360
74-     shadowImplementation(libs.semver)
75-     shadowImplementation(libs.jgit)
76-     shadowImplementation(libs.commons.io)
77-     //  Explicitly added for shadow plugin to relocate implementation as well
78-     shadowImplementation(libs.slf4j.nop)
79- 
80-     testImplementation(libs.junit.jupiter)
8161    testImplementation(libs.assertj.core)
8262    testImplementation(libs.kotlin.reflect)
8363    testImplementation(libs.ktlint.rule.engine)
8464    testImplementation(libs.archunit.junit5)
8565}
8666
67+ fun  JvmTestSuite.extendFromTest () {
68+     sources {
69+         java {
70+             source(project.sourceSets.named(" test" 
71+         }
72+         kotlin {
73+             source(project.sourceSets.named(" test" 
74+         }
75+         resources {
76+             source(project.sourceSets.named(" test" 
77+         }
78+         compileClasspath + =  project.sourceSets[" test" +  project.sourceSets[" main" 
79+         runtimeClasspath + =  project.sourceSets[" test" +  project.sourceSets[" main" 
80+ 
81+         //  make internal classes available to tests
82+         val  compilations =  project
83+             .extensions
84+             .getByType(KotlinJvmProjectExtension ::class .java).target.compilations
85+         compilations.getByName(sources.name)
86+             .associateWith(compilations.getByName(SourceSet .MAIN_SOURCE_SET_NAME ))
87+     }
88+ }
89+ 
90+ fun  getCurrentJavaVersion (): String  {
91+     return  Runtime ::class .java.getPackage().specificationVersion //  java 8
92+         ? :  Runtime ::class .java.getMethod(" version" null ).toString() //  java 9+
93+ }
94+ testing {
95+     suites {
96+         named<JvmTestSuite >(" test" 
97+             useJUnitJupiter()
98+         }
99+         listOf (8 , 11 , 17 , 21 , 25 ) //  TODO get from data feed
100+             .forEach {
101+                 register<JvmTestSuite >(" test$it " 
102+                     extendFromTest()
103+                     targets.all {
104+                         dependencies {
105+                             implementation(gradleTestKit())
106+                         }
107+                         testTask.configure {
108+                             javaLauncher.set(
109+                                 javaToolchains.launcherFor {
110+                                     languageVersion.set(JavaLanguageVersion .of(JavaVersion .current().majorVersion))
111+                                 }
112+                             )
113+                         }
114+                     }
115+                 }
116+             }
117+     }
118+ }
87119tasks.withType<Test > {
88120    dependsOn(" publishToMavenLocal" 
89-     useJUnitPlatform()
90121    maxParallelForks =  6  //  no point in this being higher than the number of gradle workers
91122
92123    //  Set the system property for the project version to be used in the tests
@@ -110,15 +141,8 @@ tasks.withType<Test> {
110141            maxFailures.set(10 )
111142        }
112143    }
113- 
114-     javaLauncher.set(
115-         javaToolchains.launcherFor {
116-             languageVersion.set(JavaLanguageVersion .of(JavaVersion .current().majorVersion))
117-         }
118-     )
119144}
120145
121- val  relocateShadowJar =  tasks.register<ConfigureShadowRelocation >(" relocateShadowJar" 
122146val  shadowJarTask =  tasks.named<ShadowJar >(" shadowJar" 
123147    manifest {
124148        attributes(
@@ -128,16 +152,12 @@ val shadowJarTask = tasks.named<ShadowJar>("shadowJar") {
128152            " Implementation-Vendor-Id" 
129153        )
130154    }
131-     //  Enable package relocation in resulting shadow jar
132-     relocateShadowJar.get().apply  {
133-         prefix =  " $pluginGroup .shadow" 
134-         target =  this @named
135-     }
136- 
137-     dependsOn(relocateShadowJar)
138-     minimize()
139-     archiveClassifier.set(" " 
140-     configurations =  listOf (shadowImplementation)
155+     relocate(" com.googlecode.javaewah" " $pluginGroup .shadow.com.googlecode.javaewah" 
156+     relocate(" net.swiftzer" " $pluginGroup .shadow.net.swiftzer" 
157+     relocate(" org.apache.commons.io" " $pluginGroup .shadow.org.apache.commons.io" 
158+     relocate(" org.eclipse.jgit" " $pluginGroup .shadow.org.eclipse.jgit" 
159+     relocate(" org.slf4j" " $pluginGroup .shadow.org.slf4j" 
160+     archiveClassifier.set(null )
141161}
142162
143163//  Add shadow jar to the Gradle module metadata api and runtime configurations
@@ -150,7 +170,7 @@ configurations {
150170
151171tasks.whenTaskAdded {
152172    if  (name ==  " publishPluginJar" ||  name ==  " generateMetadataFileForPluginMavenPublication" 
153-         dependsOn(tasks.named(" shadowJar " 
173+         dependsOn(tasks.named(" jar " 
154174    }
155175}
156176
@@ -162,11 +182,11 @@ tasks.named("jar").configure {
162182val  ensureDependenciesAreInlined by tasks.registering {
163183    description =  " Ensures all declared dependencies are inlined into shadowed jar" 
164184    group =  HelpTasksPlugin .HELP_GROUP 
165-     dependsOn(tasks.shadowJar)
185+     dependsOn(tasks.named< Jar >( " shadowJar" ) )
166186
167187    doLast {
168188        val  nonInlinedDependencies =  mutableListOf<String >()
169-         zipTree(tasks.shadowJar.flatMap { it.archiveFile }).visit {
189+         zipTree(tasks.named< Jar >( " shadowJar" ) .flatMap { it.archiveFile }).visit {
170190            if  (! isDirectory) {
171191                val  path =  relativePath
172192                if  (! path.startsWith(" META-INF" && 
@@ -234,18 +254,22 @@ fun setupPublishingEnvironment() {
234254
235255setupPublishingEnvironment()
236256
237- configurations.named(" implementation " 
257+ configurations.named(" runtimeClasspath " 
238258    attributes {
239259        attribute(GradlePluginApiVersion .GRADLE_PLUGIN_API_VERSION_ATTRIBUTE , objects.named(" 7.4" 
240260    }
241261}
242262
243263gradlePlugin {
264+     vcsUrl =  " https://github.com/JLLeitschuh/ktlint-gradle" 
265+     website =  vcsUrl
266+     description =  " Provides a convenient wrapper plugin over the ktlint project." 
244267    (plugins) {
245268        register(" ktlintPlugin" 
246269            id =  " org.jlleitschuh.gradle.ktlint" 
247270            implementationClass =  " org.jlleitschuh.gradle.ktlint.KtlintPlugin" 
248271            displayName =  " Ktlint Gradle Plugin" 
272+             tags =  listOf (" ktlint" " kotlin" " linting" 
249273        }
250274    }
251275}
@@ -254,46 +278,12 @@ tasks.named<ValidatePlugins>("validatePlugins").configure {
254278    enableStricterValidation =  true 
255279}
256280
257- //  Need to move publishing configuration into afterEvaluate {}
258- //  to override changes done by "com.gradle.plugin-publish" plugin in afterEvaluate {} block
259- //  See PublishPlugin class for details
260- afterEvaluate {
261-     publishing {
262-         publications {
263-             withType<MavenPublication > {
264-                 //  Special workaround to publish shadow jar instead of normal one. Name to override peeked here:
265-                 //  https://github.com/gradle/gradle/blob/master/subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L73
266-                 if  (name ==  " pluginMaven" 
267-                     setArtifacts(
268-                         listOf (
269-                             shadowJarTask.get()
270-                         )
271-                     )
272-                 }
273-             }
274-         }
275-     }
276- }
277- 
278- pluginBundle {
279-     vcsUrl =  " https://github.com/JLLeitschuh/ktlint-gradle" 
280-     website =  vcsUrl
281-     description =  " Provides a convenient wrapper plugin over the ktlint project." 
282-     tags =  listOf (" ktlint" " kotlin" " linting" 
283- 
284-     (plugins) {
285-         " ktlintPlugin" 
286-             displayName =  " Ktlint Gradle Plugin" 
287-         }
288-     }
289- }
290- 
291281githubRelease {
292282    setToken(providers.systemProperty(" github.secret" 
293283    owner =  " JLLeitschuh" 
294284    repo =  " ktlint-gradle" 
295285    overwrite =  true 
296-     releaseAssets(tasks.named(" shadowJar " 
286+     releaseAssets(tasks.named(" jar " 
297287
298288    fun  isPreReleaseVersion (): Boolean  {
299289        val  version =  project.version.toString()
0 commit comments