Skip to content

Commit

Permalink
Refactor release build to attempt artifact substitution.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 9, 2019
1 parent 9926e9d commit fc1c380
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
22 changes: 22 additions & 0 deletions byte-buddy-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,26 @@ plugins {
id 'java-gradle-plugin'
}

def pom = new XmlSlurper().parse(file('./pom.xml'))
def outerPom = new XmlSlurper().parse(file('../pom.xml'))

version = pom.parent.version.text().toString()

dependencies {
compile gradleApi()
// At this point, it is not given that any artifact from the Maven build can be found in a repository.
def location = new File(project.buildscript.sourceFile.getParentFile(), "../byte-buddy/target/byte-buddy-${version}.jar").canonicalFile
logger.info("Relying on ${location.absolutePath} as Byte Buddy dependency")
if (location.exists()) {
compile files(location.absolutePath)
} else {
logger.warn("${location.absolutePath} does not exist, can clean but not build project")
}
testCompile gradleTestKit()
testCompile group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testCompile(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}

apply from: './main.gradle'
21 changes: 2 additions & 19 deletions byte-buddy-gradle-plugin/main.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = pom.description.text().toString()

// Gradle cannot process all version strings such that JavaVersion.current() fails.
def raw = System.getProperty("java.version")
def current;
def current
if (!raw.startsWith("1.") && raw.contains(".")) {
current = JavaVersion.toVersion(raw.substring(0, raw.indexOf('.')))
} else {
Expand Down Expand Up @@ -42,23 +42,6 @@ repositories {
mavenCentral()
}

dependencies {
compile gradleApi()
// At this point, it is not given that any artifact from the Maven build can be found in a repository.
def location = new File(project.buildscript.sourceFile.getParentFile(), "../byte-buddy/target/byte-buddy-${version}.jar").canonicalFile
logger.info("Relying on ${location.absolutePath} as Byte Buddy dependency")
if (location.exists()) {
compile files(location.absolutePath)
} else {
logger.warn("${location.absolutePath} does not exist, can clean but not build project")
}
testCompile gradleTestKit()
testCompile group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testCompile(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}

// Without the extras property, creating a javadoc artifact is not necessary.
if (Boolean.getBoolean('net.bytebuddy.misc.extras')) {
task javadocJar(type: Jar, dependsOn: javadoc) {
Expand All @@ -80,7 +63,7 @@ task copyLicense(type: Copy) {
from '..'
include 'LICENSE', 'NOTICE'
into "$buildDir/resources/main/META-INF"
def pattern = java.util.regex.Pattern.compile('\\$\\{([a-zA-Z0-9\\-._]+)}');
def pattern = java.util.regex.Pattern.compile('\\$\\{([a-zA-Z0-9\\-._]+)}')
filter { String line ->
def matcher = pattern.matcher(line)
def buffer = new StringBuffer()
Expand Down
38 changes: 36 additions & 2 deletions byte-buddy-gradle-plugin/release.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,44 @@ plugins {
id 'com.gradle.plugin-publish' version '0.10.0'
}

apply from: './main.gradle'

def pom = new XmlSlurper().parse(file('./pom.xml'))

version = pom.parent.version.text().toString()

project(":mavenBridge") { // pseudo-project to represent the shaded byte-buddy artifact that is only published in a later step
def artifact = objects.fileProperty().fileProvider(providers.provider {
def file = file("../byte-buddy/target/byte-buddy-${version}.jar")
if (!file.exists()) {
throw new GradleException("Cannot resolve ${version} of byte-buddy artifact which is required for a release build")
}
file
})
configurations {
mavenBridge {
canBeResolved = false
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, 'java-api'))
}
outgoing.artifact(artifact)
}
}
}

dependencies {
compile gradleApi()
implementation "net.bytebuddy:byte-buddy:${version}"
}

configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("net.bytebuddy:byte-buddy:${version}") with project(":mavenBridge")
}
}

apply from: './main.gradle'

pluginBundle {
website = 'https://bytebuddy.net'
vcsUrl = 'https://github.com/raphw/byte-buddy'
Expand Down

0 comments on commit fc1c380

Please sign in to comment.