Skip to content

Commit

Permalink
Use Gradle Toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik committed Jul 20, 2023
1 parent 17dd858 commit f417ba4
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 148 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ jobs:

- name: Build BTrace
run: |
./config_build.sh
source .java.versions
./gradlew -x test build
- name: Perform CodeQL Analysis
Expand Down
48 changes: 4 additions & 44 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,18 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Java 8
uses: actions/setup-java@v1
with:
java-version: 8
- name: Store JAVA_8_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_8_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Set up Java 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Store JAVA_17_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_17_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Set up Java 19
uses: actions/setup-java@v1
with:
java-version: 19
- name: Store JAVA_19_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_19_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Set up Java 11
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
- name: Store JAVA_11_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_11_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build
run: JAVA_HOME="$JAVA_11_HOME" ./gradlew build
run: ./gradlew build
- name: Upload build data
if: always()
uses: actions/upload-artifact@v3
Expand All @@ -72,7 +52,7 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
java: [ 8, 11, 17, 19 ]
java: [ 8, 11, 17, 20 ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -123,30 +103,10 @@ jobs:
run: chmod +x gradlew
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Set up Java 8
uses: actions/setup-java@v1
with:
java-version: 8
- name: Store JAVA_8_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_8_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Set up Java 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Store JAVA_17_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_17_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Set up Java 19
uses: actions/setup-java@v1
with:
java-version: 19
- name: Store JAVA_19_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_19_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Set up Java 11
- name: Set up Java
uses: actions/setup-java@v1
with:
java-version: 11
- name: Store JAVA_11_HOME
run: JAVA_PATH=$(which java) && echo "JAVA_11_HOME=${JAVA_PATH/\/bin\/java/\/}" >> $GITHUB_ENV
- name: Download build data
uses: actions/download-artifact@v3
with:
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,11 @@ BTrace can be used to dynamically trace a running Java program (similar to DTrac
You will need the following applications installed

* [Git](http://git-scm.com/downloads)
* __JDKs__ - JDK 8, Java 9 and Java 11 are required to be available
* (optionally, the default launcher is the bundled `gradlew` wrapper) [Gradle](http://gradle.org)

In order to ease the pre-build config the `config_build.sh` script is provided. You should run it first as `source config_build.sh` to automatically download all required JDKs and set up the corresponding `JAVA_*_HOME` env variables.

### Build

#### Java
Your __JAVA_HOME__ must point to JDK 11 (eg. __JAVA_11_HOME__)

#### Gradle
```sh
cd <btrace>
Expand Down
2 changes: 1 addition & 1 deletion btrace-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dependencies {
implementation libs.slf4j
implementation libs.asm

implementation files("${JAVA_8_HOME}/lib/tools.jar")
implementation files("${getToolsJar()}")
implementation project(':btrace-core')
implementation project(':btrace-services-api')
implementation project(':btrace-runtime')
Expand Down
2 changes: 1 addition & 1 deletion btrace-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
implementation libs.asm.tree
implementation libs.asm.util

implementation files("${JAVA_8_HOME}/lib/tools.jar")
implementation files("${getToolsJar()}")

implementation project(':btrace-core')
implementation project(':btrace-compiler')
Expand Down
2 changes: 1 addition & 1 deletion btrace-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependencies {
implementation libs.asm
implementation libs.asm.util

implementation files("${JAVA_8_HOME}/lib/tools.jar")
implementation files("${getToolsJar()}")
implementation project(path: ':btrace-core')
implementation project(path: ':btrace-runtime')
runtimeOnly project(path: ':btrace-instr')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Map<String, byte[]> compile(
options.add("-g:lines");
options.add("-deprecation");
options.add("-source");
options.add("1.7");
options.add("8");
options.add("-target");
options.add("1.7");
options.add("8");
if (sourcePath != null) {
options.add("-sourcepath");
options.add(sourcePath);
Expand Down
7 changes: 0 additions & 7 deletions btrace-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ dependencies {
implementation libs.asm.util
}

compileJava {
sourceCompatibility = 8
targetCompatibility = 8
options.fork = true
options.forkOptions.executable = "${project.property("JAVA_11_HOME")}/bin/javac"
}

processResources {
filter ReplaceTokens, tokens: [
"btrace.version": project.version,
Expand Down
10 changes: 7 additions & 3 deletions btrace-instr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ dependencies {
testImplementation project(':btrace-client')
}

compileJava {
javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

compileTestJava {
sourceCompatibility = 8
targetCompatibility = 8
options.fork = true
options.forkOptions.executable = "${project.property("JAVA_8_HOME")}/bin/javac"
options.forkOptions.executable = "${getJavac(8)}"
}

task compileTestProbes {
Expand Down
25 changes: 14 additions & 11 deletions btrace-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,36 @@ compileJava {
sourceCompatibility = 8
targetCompatibility = 8
options.fork = true
options.forkOptions.executable = "${System.getenv("JAVA_8_HOME")}/bin/javac"
javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(8))
}
}

compileJava9Java {
sourceCompatibility = 9
targetCompatibility = 9
options.fork = true
options.forkOptions.executable = "${System.getenv("JAVA_11_HOME")}/bin/javac"
options.forkOptions.javaHome = file("${System.getenv("JAVA_11_HOME")}")
javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
}
options.compilerArgs.addAll(['--add-exports', 'java.base/jdk.internal.reflect=ALL-UNNAMED', '--add-exports', 'java.base/jdk.internal.perf=ALL-UNNAMED'])
}

compileJava11Java {
sourceCompatibility = 11
targetCompatibility = 11
options.fork = true
options.forkOptions.executable = "${System.getenv("JAVA_11_HOME")}/bin/javac"
options.forkOptions.javaHome = file("${System.getenv("JAVA_11_HOME")}")
javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
}
options.compilerArgs.addAll(['--add-exports', 'java.base/jdk.internal.reflect=ALL-UNNAMED', '--add-exports', 'java.base/jdk.internal.perf=ALL-UNNAMED'])
}

compileJava15Java {
sourceCompatibility = 11
targetCompatibility = 11
options.fork = true
options.forkOptions.executable = "${System.getenv("JAVA_17_HOME")}/bin/javac"
options.forkOptions.javaHome = file("${System.getenv("JAVA_17_HOME")}")
sourceCompatibility = 15
targetCompatibility = 15
javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
options.compilerArgs.addAll(['--add-exports', 'java.base/jdk.internal.reflect=ALL-UNNAMED', '--add-exports', 'java.base/jdk.internal.perf=ALL-UNNAMED'])
}

Expand Down
44 changes: 25 additions & 19 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,38 @@ apply plugin: 'idea'
project.group = 'org.openjdk.btrace'
project.version = '2.3.0-SNAPSHOT'

sourceCompatibility = '8'
targetCompatibility = '8'

if (!project.hasProperty("JAVA_8_HOME")) {
project.ext.setProperty("JAVA_8_HOME", System.getenv("JAVA_8_HOME"))
}
if (!project.hasProperty("JAVA_9_HOME")) {
project.ext.setProperty("JAVA_9_HOME", System.getenv("JAVA_9_HOME"))
}
if (!project.hasProperty("JAVA_11_HOME")) {
project.ext.setProperty("JAVA_11_HOME", System.getenv("JAVA_11_HOME"))
}
if (!project.hasProperty("JAVA_16_HOME")) {
project.ext.setProperty("JAVA_16_HOME", System.getenv("JAVA_16_HOME"))
}

buildscript {
repositories {
mavenCentral()
}
}

ext.getToolsJar = {
return javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
}.get().metadata.installationPath.file("lib/tools.jar")
}

ext.getJavac = { int version = 11 ->
return javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(version))
}.get().metadata.installationPath.file("bin/javac")
}

ext.getJavadoc = {
return javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(8))
}.get().metadata.installationPath.file("bin/javadoc")
}

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

compileJava {
options.fork = true
options.forkOptions.executable = "${project.property("JAVA_8_HOME")}/bin/javac"
sourceCompatibility = 8
targetCompatibility = 8
javaCompiler = javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
}
}

repositories {
Expand All @@ -53,7 +58,8 @@ String mavenArtifactId = name

javadoc {
options.addStringOption('Xdoclint:all,-missing', '-quiet')
executable = "${JAVA_8_HOME}/bin/javadoc"
options.encoding("UTF-8")
executable = "${getJavadoc()}"
failOnError true
}

Expand Down
52 changes: 0 additions & 52 deletions config_build.sh

This file was deleted.

1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencyResolutionManagement {
plugin ('ospackage', 'com.netflix.nebula.ospackage').version('11.3.0')
plugin ('shadow', 'com.github.johnrengelman.shadow').version('7.1.2')
plugin ('sdkman-vendors', 'io.sdkman.vendors').version('3.0.0')
plugin ('foojay-resolver', 'org.gradle.toolchains.foojay-resolver-convention').version('0.5.0')

plugin ('jmh', 'me.champeau.jmh').versionRef('jmhGradlePlugin')

Expand Down

0 comments on commit f417ba4

Please sign in to comment.