Skip to content

Commit

Permalink
Create a single variant publication compiled against Gradle 6.x but c…
Browse files Browse the repository at this point in the history
…ompatible and tested with Gradle 7.x
  • Loading branch information
chali committed Jun 9, 2021
1 parent c09ceb7 commit 46ae2ef
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 297 deletions.
190 changes: 44 additions & 146 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
* limitations under the License.
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'nebula.plugin-plugin' version '15.4.1'
id 'nebula.kotlin' version '1.3.70'
id 'com.github.johnrengelman.shadow' version '7.0.0'
id 'java-gradle-plugin'
id 'java-library'
}

description 'Pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts'
Expand All @@ -41,12 +38,21 @@ configurations {
testRuntimeClasspath.extendsFrom plugin
}

facets {
gradle6Test {
parentSourceSet = 'main'
}
}

gradle6Test {
useJUnit()
}

dependencies {
compileOnly 'com.netflix.nebula:gradle-info-plugin:latest.release'
compileOnly 'dev.gradleplugins:gradle-api:6.8.3'
api 'com.netflix.nebula:nebula-gradle-interop:latest.release'
api 'org.apache.maven:maven-model-builder:3.+'
api 'com.google.guava:guava:19.0'
api 'org.codehaus.gpars:gpars:1.2.1'

plugin('org.ow2.asm:asm:7.+') {
version {
Expand All @@ -70,12 +76,23 @@ dependencies {
}
plugin 'org.eclipse.jdt:core:3.1.1'

plugin 'org.codehaus.gpars:gpars:1.2.1'

compileOnly "com.netflix.nebula:nebula-test:9.+"

testImplementation gradleTestKit()
testImplementation 'org.ow2.asm:asm-util:5.2'
testImplementation 'joda-time:joda-time:latest.release'
testImplementation 'com.netflix.nebula:gradle-info-plugin:latest.release'

gradle6TestImplementation "com.netflix.nebula:nebula-test:9.+"
gradle6TestRuntimeOnly project.getLayout().files(pluginUnderTestMetadata)
gradle6TestImplementation "dev.gradleplugins:gradle-test-kit:6.8.3"
}

afterEvaluate {
configurations.named("implementation") {
dependencies.remove(project.dependencies.gradleApi())
}
}

pluginBundle {
Expand Down Expand Up @@ -121,6 +138,27 @@ shadowJar {
jar.enabled = false
jar.dependsOn shadowJar

publishing {
publications {
withType(MavenPublication) {
pom.withXml {
asNode()
.dependencies
.dependency
.findAll {
// JGit is shaded inside the distribution, and we want the others to act as 'provided'
[
'core', 'org.eclipse.jgit', 'CodeNarc', // shaded and relocated
'asm', 'asm-commons', 'commons-lang', // shaded and relocated
'spock-core', 'nebula-test', 'junit', // act as 'provided'
].contains(it.artifactId.text())
}
.each { it.parent().remove(it) }
}
}
}
}

tasks.withType(Test) {
maxHeapSize = '512m'
maxParallelForks = 4
Expand Down Expand Up @@ -161,144 +199,4 @@ test.dependsOn 'shadowJar', 'generatePomFileForNebulaPublication'

nebulaRelease {
releaseBranchPatterns.add("beta")
}

//gradle metadata can be allowed in this project since we manually curate content of api/runtime Elements
project.tasks.withType(GenerateModuleMetadata) { task ->
task.enabled = true
}

sourceSets {
main {
groovy {
srcDirs("src/gradle7Only/groovy")
}
}
gradle6 {
groovy {
srcDirs("src/main/groovy")
srcDirs("src/gradle6Only/groovy")
}
kotlin {
srcDirs("src/main/kotlin")
}
resources {
srcDirs("src/main/resources")
}
}
}

facets {
gradle6Test {
parentSourceSet = 'gradle6'
}
}

tasks.named('compileGradle6Groovy') {
classpath = sourceSets.gradle6.compileClasspath
}
tasks.named('compileGradle6Kotlin') {
classpath += files(sourceSets.gradle6.groovy.classesDirectory)
}


java {
registerFeature('gradle6') {
usingSourceSet(sourceSets.gradle6)
capability(project.group.toString(), project.name, project.version.toString())
}
}

['apiElements', 'runtimeElements'].each { configuration ->
configurations[configuration].attributes {
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE,
objects.named(GradlePluginApiVersion, '7.0'))
}
}

def localToProjectAttribute = Attribute.of("org.jetbrains.kotlin.localToProject", String)
def typeAttribute = Attribute.of("org.jetbrains.kotlin.platform.type", String)

['gradle6ApiElements', 'gradle6RuntimeElements'].each { configuration ->
configurations[configuration].attributes {
attribute(localToProjectAttribute, 'public')
attribute(typeAttribute, 'jvm')
}
}

tasks.named(sourceSets.gradle6.processResourcesTaskName) {
def copyPluginDescriptors = rootSpec.addChild()
copyPluginDescriptors.into('META-INF/gradle-plugins')
copyPluginDescriptors.from(tasks.pluginDescriptors)
}

dependencies {
gradle6CompileOnly 'com.netflix.nebula:gradle-info-plugin:latest.release'
gradle6CompileOnly 'dev.gradleplugins:gradle-api:6.8.3'
gradle6Api 'com.netflix.nebula:nebula-gradle-interop:latest.release'
gradle6Api 'org.apache.maven:maven-model-builder:3.+'
gradle6Api 'com.google.guava:guava:19.0'
gradle6Api 'org.codehaus.gpars:gpars:1.2.1'

gradle6CompileOnly "com.netflix.nebula:nebula-test:8.+"

gradle6TestImplementation "com.netflix.nebula:nebula-test:8.+"
gradle6TestImplementation "dev.gradleplugins:gradle-test-kit:6.8.3"
}

configurations {
gradle6CompileClasspath.extendsFrom plugin
gradle6RuntimeClasspath.extendsFrom plugin
}

task gradle6PluginUnderTestMetadata(type: PluginUnderTestMetadata) {
outputDirectory = file("$buildDir/gradle6PluginUnderTestMetadata")
pluginClasspath.from(sourceSets.gradle6.runtimeClasspath)
}

dependencies {
gradle6TestRuntimeOnly project.getLayout().files(gradle6PluginUnderTestMetadata)
}

gradle6Test {
dependsOn gradle6PluginUnderTestMetadata
useJUnit()
}

task gradle6ShadowJar(type: ShadowJar) {
//exclude signatures. this is done by shadow jar plugin for existing task, custom task needs explicit declaration
exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'module-info.class')
from sourceSets.gradle6.output
configurations = [project.configurations.plugin]
archiveClassifier = 'gradle6'
dependencies {
include(dependency('org.eclipse.jdt:core'))
include(dependency('org.eclipse.jgit:org.eclipse.jgit'))
include(dependency('commons-lang:commons-lang'))
include(dependency('org.codenarc:CodeNarc'))
include(dependency('org.ow2.asm:asm'))
include(dependency('org.ow2.asm:asm-commons'))
}
relocate 'org.eclipse.jdt', 'com.netflix.nebula.lint.jdt'
relocate 'org.eclipse.jgit', 'com.netflix.nebula.lint.jgit'
relocate 'org.apache.commons.lang', 'com.netflix.nebula.lint.commons.lang'
relocate 'org.codenarc', 'com.netflix.nebula.lint.org.codenarc'
relocate 'org.objectweb.asm', 'com.netflix.nebula.lint.org.objectweb.asm'
relocate 'org.objectweb.asm.commons', 'com.netflix.nebula.lint.org.objectweb.asm.commons'

// powerassert is packed inside codenarc without relocation for some reason
relocate 'org.codehaus.groovy.transform.powerassert', 'com.netflix.nebula.lint.org.codehaus.groovy.transform.powerassert'
}

//remove original gradle6Jar from building and publishing
configurations.gradle6ApiElements.outgoing.artifacts.clear()
configurations.gradle6RuntimeElements.outgoing.artifacts.clear()

artifacts {
gradle6ApiElements(gradle6ShadowJar)
gradle6RuntimeElements(gradle6ShadowJar)
}

components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements) {
skip()
}
Loading

0 comments on commit 46ae2ef

Please sign in to comment.