Skip to content

Commit

Permalink
Inject versions into Gradle and Maven builds more idiomatically
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 28, 2024
1 parent 7a4ee8e commit 164f590
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id("org.graalvm.buildtools.native")
}

val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
val jupiterVersion: String by project
val platformVersion: String by project

repositories {
maven { url = uri(file(System.getProperty("maven.repo"))) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ repositories {
mavenCentral()
}

// grab jupiter version from system environment
val jupiterVersion = System.getenv("JUNIT_JUPITER_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
val jupiterVersion: String by project
val platformVersion: String by project

dependencies {
testImplementation(kotlin("stdlib-jdk8"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,8 @@ plugins {
java
}

// grab jupiter version from system environment
val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")

// emit default file encoding to a file
file("file.encoding.txt").writeText(System.getProperty("file.encoding"))

// emit more Java runtime information
file("java.runtime.txt").writeText("""
java.version=${System.getProperty("java.version")}
""")

// emit versions of JUnit groups
file("junit.versions.txt").writeText("""
jupiterVersion=$jupiterVersion
vintageVersion=$vintageVersion
platformVersion=$platformVersion
""")
val jupiterVersion: String by project
val platformVersion: String by project

repositories {
maven { url = uri(file(System.getProperty("maven.repo"))) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ plugins {
java
}

// grab jupiter version from system environment
val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
val jupiterVersion: String by project
val platformVersion: String by project

repositories {
maven { url = uri(file(System.getProperty("maven.repo"))) }
Expand Down
2 changes: 0 additions & 2 deletions platform-tooling-support-tests/projects/java-versions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>${env.JUNIT_JUPITER_VERSION}</junit.jupiter.version>
<junit.platform.version>${env.JUNIT_PLATFORM_VERSION}</junit.platform.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.bom.version>${env.JUNIT_JUPITER_VERSION}</junit.bom.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.bom.version>${env.JUNIT_JUPITER_VERSION}</junit.bom.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>${env.JUNIT_JUPITER_VERSION}</junit.jupiter.version>
<junit.vintage.version>${env.JUNIT_VINTAGE_VERSION}</junit.vintage.version>
<junit.platform.version>${env.JUNIT_PLATFORM_VERSION}</junit.platform.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ plugins {
java
}

// grab jupiter version from system environment
val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION")
val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION")
val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
val jupiterVersion: String by project
val platformVersion: String by project

repositories {
maven { url = uri(file(System.getProperty("maven.repo"))) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ repositories {
mavenCentral()
}

val platformVersion: String by project
val vintageVersion: String by project

dependencies {
val junit4Version = System.getProperty("junit4Version", "4.12")
testImplementation("junit:junit:$junit4Version")

val vintageVersion = System.getenv("JUNIT_VINTAGE_VERSION") ?: "5.3.2"
testImplementation("org.junit.vintage:junit-vintage-engine:$vintageVersion") {
exclude(group = "junit")
because("we want to override it to test against different versions")
}

val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$platformVersion")
}

Expand Down
3 changes: 1 addition & 2 deletions platform-tooling-support-tests/projects/vintage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<vintageVersion>${env.JUNIT_VINTAGE_VERSION}</vintageVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${vintageVersion}</version>
<version>${junit.vintage.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,28 @@ public static ProcessStarter javaCommand(Path javaHome, String commandName) {
}

public static ProcessStarter gradlew() {
var starter = new ProcessStarter() //
return new ProcessStarter() //
.executable(Path.of("..").resolve(windowsOrOtherExecutable("gradlew.bat", "gradlew"))) //
.putEnvironment("JAVA_HOME", getGradleJavaHome().orElseThrow(TestAbortedException::new));
return withCommonEnvironmentVariables(starter);
.putEnvironment("JAVA_HOME", getGradleJavaHome().orElseThrow(TestAbortedException::new)) //
.addArguments("-PjupiterVersion=" + Helper.version("junit-jupiter")) //
.addArguments("-PvintageVersion=" + Helper.version("junit-vintage")) //
.addArguments("-PplatformVersion=" + Helper.version("junit-platform"));
}

public static ProcessStarter maven() {
var starter = new ProcessStarter() //
return new ProcessStarter() //
.executable(Path.of(System.getProperty("mavenDistribution")).resolve("bin").resolve(
windowsOrOtherExecutable("mvn.cmd", "mvn")));
return withCommonEnvironmentVariables(starter);
windowsOrOtherExecutable("mvn.cmd", "mvn"))) //
.addArguments("-Djunit.jupiter.version=" + Helper.version("junit-jupiter")) //
.addArguments("-Djunit.bom.version=" + Helper.version("junit-jupiter")) //
.addArguments("-Djunit.vintage.version=" + Helper.version("junit-vintage")) //
.addArguments("-Djunit.platform.version=" + Helper.version("junit-platform"));
}

private static String windowsOrOtherExecutable(String cmdOrExe, String other) {
return OS.current() == OS.WINDOWS ? cmdOrExe : other;
}

private static ProcessStarter withCommonEnvironmentVariables(ProcessStarter starter) {
starter.putEnvironment("JUNIT_JUPITER_VERSION", Helper.version("junit-jupiter"));
starter.putEnvironment("JUNIT_VINTAGE_VERSION", Helper.version("junit-vintage"));
starter.putEnvironment("JUNIT_PLATFORM_VERSION", Helper.version("junit-platform"));
return starter;
}

public static Optional<Path> getGradleJavaHome() {
return Helper.getJavaHome(System.getProperty("gradle.java.version"));
}
Expand Down

0 comments on commit 164f590

Please sign in to comment.