Skip to content

Commit

Permalink
Another take at the Gradle build with Java 6/7 build-retention.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 10, 2019
1 parent 0bdeeda commit 865cd2e
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 112 deletions.
File renamed without changes.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ jobs:
architecture: x64
- name: Build project
run: ./mvnw verify -Pintegration -Pjava${{ matrix.java }}
if: matrix.java < 13
if: matrix.java < 14
- name: Build project (without Gradle)
run: ./mvnw verify -Pintegration -Pjava${{ matrix.java }} -pl !byte-buddy-gradle-plugin
if: matrix.java > 12
if: matrix.java > 13
hotspot-unsupported:
name: HotSpot (unsupported)
strategy:
Expand Down Expand Up @@ -90,12 +90,12 @@ jobs:
run: |
. ./.github/scripts/install-jdk.sh --url "https://api.adoptopenjdk.net/v2/binary/releases/openjdk${{ matrix.java }}?openjdk_impl=openj9&os=linux&arch=x64&release=latest&type=jdk&heap_size=normal"
./mvnw verify -Pintegration -Pjava${{ matrix.java }}
if: matrix.java < 13
if: matrix.java < 14
- name: Install JDK and build project (without Gradle)
run: |
. ./.github/scripts/install-jdk.sh --url "https://api.adoptopenjdk.net/v2/binary/releases/openjdk${{ matrix.java }}?openjdk_impl=openj9&os=linux&arch=x64&release=latest&type=jdk&heap_size=normal"
./mvnw verify -Pintegration -Pjava${{ matrix.java }} -pl !byte-buddy-gradle-plugin
if: matrix.java > 12
if: matrix.java > 13
coverage:
name: Coverage
runs-on: ubuntu-18.04
Expand Down
2 changes: 1 addition & 1 deletion byte-buddy-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions byte-buddy-dep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<executions>
<execution>
<phase>compile</phase>
Expand All @@ -116,13 +116,13 @@
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<plugin>net.bytebuddy.build.HashCodeAndEqualsPlugin$WithNonNullableFields</plugin>
</transformation>
<transformation>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.2</version>
<version>1.10.4</version>
<plugin>net.bytebuddy.build.CachedReturnPlugin</plugin>
</transformation>
</transformations>
Expand Down
62 changes: 46 additions & 16 deletions byte-buddy-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
plugins {
id 'java'
id 'java-gradle-plugin'
id 'com.gradle.plugin-publish' version '0.10.1'
}

def pom = new XmlSlurper().parse(file('./pom.xml'))
def outerPom = new XmlSlurper().parse(file('../pom.xml'))
apply from: './main.gradle'

if (legacy) {
throw new GradleException("Current JDK version only supports simple build (--build-file build.simple.gradle)");
}

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")
if (gradle.gradleVersion.startsWith("2.")) { // support legacy version
dependencies {
compile gradleApi()
compile "net.bytebuddy:byte-buddy:${version}"
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'
}
}
} else {
dependencies {
implementation gradleApi()
implementation "net.bytebuddy:byte-buddy:${version}"
testImplementation gradleTestKit()
testImplementation group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testImplementation(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}
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'
}

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'
tags = ['Byte Buddy', 'bytecode', 'enhancement']
}

gradlePlugin {
plugins {
byteBuddyPlugin {
id = pom.parent.groupId.text().toString() + '.' + pom.artifactId.text().toString()
displayName = pom.name.text().toString()
description = pom.description.text().toString()
implementationClass = 'net.bytebuddy.build.gradle.ByteBuddyPlugin'
}
}
}
42 changes: 42 additions & 0 deletions byte-buddy-gradle-plugin/build.simple.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'java'
id 'java-gradle-plugin'
}

apply from: './main.gradle'

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

// 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 (gradle.gradleVersion.startsWith("2.")) { // support legacy version
dependencies {
compile gradleApi()
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'
}
}
} else {
dependencies {
implementation gradleApi()
if (location.exists()) {
implementation files(location.absolutePath)
} else {
logger.warn("${location.absolutePath} does not exist, can clean but not build project")
}
testImplementation gradleTestKit()
testImplementation group: 'junit', name: 'junit', version: outerPom.properties.'version.junit'
testImplementation(group: 'org.mockito', name: 'mockito-core', version: outerPom.properties.'version.mockito') {
exclude group: 'net.bytebuddy'
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-5.4.1-bin.zip
distributionUrl=gradle-6.0.1-bin.zip
4 changes: 2 additions & 2 deletions byte-buddy-gradle-plugin/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ case "`uname`" in
esac

# Java 6 and 7 are no longer supported by Gradle 5 which is why we are using an old version of Gradle if those are detected.
if `java -fullversion 2>&1 >/dev/null | awk '{print $4}' | grep -Eq "^\"1\.[67]\."`; then
if `$JAVA_HOME/bin/java -fullversion 2>&1 >/dev/null | awk '{print $4}' | grep -Eq "^\"1\.[67]\."`; then
GRADLE_VERSION="2.14.1"
else
GRADLE_VERSION="5.4.1"
GRADLE_VERSION="6.0.1"
fi

CLASSPATH=$APP_HOME/gradle/${GRADLE_VERSION}/gradle-wrapper.jar
Expand Down
4 changes: 2 additions & 2 deletions byte-buddy-gradle-plugin/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ set CMD_LINE_ARGS=%*
@rem Setup the command line

@rem Java 6 and 7 are no longer supported by Gradle 5 which is why we are using an old version of Gradle if those are detected.
for /f tokens^=2-5^ delims^=.-_^" %%j in ('java -fullversion 2^>^&1') do set "JAVA_VERSION_STRING=%%j%%k%%l%%m"
for /f tokens^=2-5^ delims^=.-_^" %%j in ('%JAVA_HOME%\bin\java -fullversion 2^>^&1') do set "JAVA_VERSION_STRING=%%j%%k%%l%%m"
IF "%JAVA_VERSION_STRING:~0,3%"=="160" (
set "GRADLE_VERSION=2.14.1"
) ELSE (IF "%JAVA_VERSION_STRING:~0,3%"=="170" (
set "GRADLE_VERSION=2.14.1"
) ELSE (
set "GRADLE_VERSION=5.4.1"
set "GRADLE_VERSION=6.0.1"
))

set CLASSPATH=%APP_HOME%\gradle\%GRADLE_VERSION%\gradle-wrapper.jar
Expand Down
6 changes: 4 additions & 2 deletions byte-buddy-gradle-plugin/main.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def pom = new XmlSlurper().parse(file('./pom.xml'))
def outerPom = new XmlSlurper().parse(file('../pom.xml'))
ext.pom = new XmlSlurper().parse(file('./pom.xml'))
ext.outerPom = new XmlSlurper().parse(file('../pom.xml'))

group = pom.parent.groupId.text().toString()
version = pom.parent.version.text().toString()
Expand All @@ -14,6 +14,8 @@ if (!raw.startsWith("1.") && raw.contains(".")) {
current = JavaVersion.toVersion(raw)
}

ext.legacy = current < JavaVersion.VERSION_1_8

def sourceVersion = System.getProperty("net.bytebuddy.gradle.version.source")
if (sourceVersion != null) {
sourceCompatibility = JavaVersion.toVersion(sourceVersion)
Expand Down
18 changes: 18 additions & 0 deletions byte-buddy-gradle-plugin/mavenBridge/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version = pom.parent.version.toString()

configurations {
mavenBridge {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, 'java-runtime'))
}
outgoing.artifact(objects.fileProperty().fileProvider(providers.provider {
def file = rootProject.file("../byte-buddy/target/byte-buddy-${version}.jar")
if (!file.exists()) {
throw new GradleException("Cannot resolve ${version} of byte-buddy artifact what is required for a substitution")
}
file
}))
}
}
19 changes: 3 additions & 16 deletions byte-buddy-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

<properties>
<version.plugin.antrun>1.8</version.plugin.antrun>
<version.plugin.gradlerun>1.0.10</version.plugin.gradlerun>
<version.plugin.directory>0.2</version.plugin.directory>
<version.gradle>4.5</version.gradle>
<exec.gradle>gradlew</exec.gradle>
<!-- Actual values must be set via settings.xml or using command line arguments since they cannot be published. -->
<gradle.publish.key />
Expand Down Expand Up @@ -82,6 +79,7 @@
<executable>${project.basedir}/${exec.gradle}</executable>
<arguments>
<argument>clean</argument>
<argument>--build-file=build.simple.gradle</argument>
<argument>--info</argument>
</arguments>
</configuration>
Expand All @@ -97,6 +95,7 @@
<arguments>
<argument>build</argument>
<argument>javadocJar</argument>
<argument>--build-file=build.simple.gradle</argument>
<argument>--info</argument>
<argument>-Dnet.bytebuddy.test.integration=${bytebuddy.integration}</argument>
<argument>-Dnet.bytebuddy.misc.extras=${bytebuddy.extras}</argument>
Expand All @@ -115,7 +114,7 @@
<executable>${project.basedir}/${exec.gradle}</executable>
<arguments>
<argument>publishPlugins</argument>
<argument>--build-file=release.gradle</argument>
<argument>--build-file=build.gradle</argument>
<argument>--info</argument>
<argument>-Dnet.bytebuddy.test.integration=${bytebuddy.integration}</argument>
<argument>-Dnet.bytebuddy.misc.extras=${bytebuddy.extras}</argument>
Expand Down Expand Up @@ -150,18 +149,6 @@
</build>

<profiles>
<profile>
<id>gradle-legacy</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.6</jdk>
</activation>
<properties>
<version.plugin.gradlerun>1.0.9</version.plugin.gradlerun>
<version.gradle>2.14.1</version.gradle>
</properties>
</profile>

<profile>
<id>gradle-windows</id>
<activation>
Expand Down
60 changes: 0 additions & 60 deletions byte-buddy-gradle-plugin/release.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.*;

public class ByteBuddyExtensionTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.junit.rules.TestRule;
import org.mockito.Mock;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

public class PostCompilationActionTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down

0 comments on commit 865cd2e

Please sign in to comment.