Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target Java 8 in Java 9 build #4037

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.gradle
.idea
.project
.remote-libs/
.settings
.checkstyle

Expand Down
22 changes: 14 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ task validateYamls(group: 'verification', description: 'Validates YAML files.')
}

subprojects {
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'net.ltgt.errorprone'

apply from: "${rootProject.projectDir}/gradle/scripts/release.gradle"
apply from: "${rootProject.projectDir}/gradle/scripts/remote-lib.gradle"
apply from: "${rootProject.projectDir}/gradle/scripts/version.gradle"

group = 'triplea'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a regression from when I was consolidating the buildscripts. The sourceCompatibility and targetCompatibility properties must be set after the java plugin is applied, otherwise they will be overwritten with the version of the running JVM.

Expand All @@ -41,14 +50,6 @@ subprojects {
sonatypeGoodiesPrefsVersion = '2.2.4'
}

apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'net.ltgt.errorprone'

apply from: "${rootProject.projectDir}/gradle/scripts/release.gradle"
apply from: "${rootProject.projectDir}/gradle/scripts/version.gradle"

repositories {
jcenter()
maven {
Expand Down Expand Up @@ -87,6 +88,11 @@ subprojects {
]
options.encoding = 'UTF-8'
options.incremental = true

// workaround for https://github.com/gradle/gradle/issues/2510
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
options.compilerArgs += ['--release', '8']
}
}

check {
Expand Down
9 changes: 9 additions & 0 deletions game-headed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ mainClassName = 'org.triplea.game.headed.runner.HeadedGameRunner'
version = getEngineVersion()

ext {
javaFxRuntimeUrl = 'https://github.com/triplea-game/assets/raw/master/javafx/jfxrt-1.8.0_181.jar'
releasesDir = file("$buildDir/releases")
testFxVersion = '4.0.13-alpha'
}

dependencies {
compile project(':game-core')

if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
compileOnly remoteLib(javaFxRuntimeUrl)
}

testCompile project(':test-common')
testCompile "org.sonatype.goodies:goodies-prefs:$sonatypeGoodiesPrefsVersion"
testCompile "org.testfx:testfx-core:$testFxVersion"
testCompile "org.testfx:testfx-junit5:$testFxVersion"

if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
testCompileOnly remoteLib(javaFxRuntimeUrl)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the testCompileOnly configuration does not inherit from the compileOnly configuration. Research shows this appears to be a design decision by the Gradle maintainers (to be different than how Maven works with its provideCompile configuration).

}

if (JavaVersion.current() == JavaVersion.VERSION_1_9) {
testRuntimeOnly 'org.testfx:openjfx-monocle:jdk-9+181'
} else if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
Expand Down
32 changes: 32 additions & 0 deletions gradle/scripts/remote-lib.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.nio.file.Paths

import de.undercouch.gradle.tasks.download.DownloadAction

buildscript {
repositories {
jcenter()
}

dependencies {
classpath group: 'de.undercouch', name: 'gradle-download-task', version: '3.4.3'
}
}

def remoteLibsDir = file('.remote-libs')

ext.remoteLib = { url ->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I had to re-introduce this functionality in order to download the JavaFX dependency from the assets repo. To keep things clean, I extracted all the related code into this standalone script.

def file = file("$remoteLibsDir/${Paths.get(new URI(url).path).fileName}")
def download = new DownloadAction(project)
download.src url
download.dest file
download.overwrite false
download.execute()
files(file)
}

task cleanRemoteLibs(
type: Delete,
group: LifecycleBasePlugin.BUILD_GROUP,
description: 'Deletes the remote libraries directory.') {
delete remoteLibsDir
}