Skip to content

Commit

Permalink
Fix deprecations in Gradle 8.7 (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Mar 23, 2024
1 parent 6a42045 commit e441c6b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions build.xml
Expand Up @@ -111,6 +111,9 @@
<property name="maven-plugin-plugin.version" value="3.4"/>
<property name="maven-compiler-plugin.version" value="3.8.1"/>

<!-- extra properties (prefixed by "gradle." added to gradle.properties during testing: -->
<property name="gradle.org.gradle.warning.mode" value="all"/>

<!-- with fork=false this somehow takes endless to download the internet, so let's fork - and slow down in an other way (startup) -->
<property name="maven.fork" value="true"/>

Expand Down
Expand Up @@ -46,9 +46,12 @@ public class ForbiddenApisPlugin extends ForbiddenApisPluginBase {
group = JavaBasePlugin.VERIFICATION_GROUP;
}

// retrieve Java Extension, if it is not available fallback to project convention:
def javaExtension = project.extensions.findByName('java') ?: project

// Gradle is buggy with it's JavaVersion enum: We use majorVersion property before Java 11 (6,7,8,9,10) and for later we use toString() to be future-proof:
Closure targetCompatibilityGetter = { (project.targetCompatibility?.hasProperty('java11Compatible') && project.targetCompatibility?.java11Compatible) ?
project.targetCompatibility.toString() : project.targetCompatibility?.majorVersion };
Closure targetCompatibilityGetter = { (javaExtension.targetCompatibility?.hasProperty('java11Compatible') && javaExtension.targetCompatibility?.java11Compatible) ?
javaExtension.targetCompatibility.toString() : javaExtension.targetCompatibility?.majorVersion };

// Define our tasks (one for each SourceSet):
project.sourceSets.all{ sourceSet ->
Expand Down
11 changes: 10 additions & 1 deletion src/test/gradle/build.gradle
Expand Up @@ -29,7 +29,16 @@ buildscript {
apply plugin: 'java'
apply plugin: 'de.thetaphi.forbiddenapis'

sourceCompatibility = forbiddenSourceCompatibility
if (project.extensions.findByName('java')) {

java {
sourceCompatibility = JavaVersion.toVersion(forbiddenSourceCompatibility)
}

} else {
// TODO: Remove this after Gradle 4.10
sourceCompatibility = JavaVersion.toVersion(forbiddenSourceCompatibility)
}

sourceSets {
main {
Expand Down

0 comments on commit e441c6b

Please sign in to comment.