From c9f61fa653b8c788237433193bc4c67a7af51125 Mon Sep 17 00:00:00 2001 From: Benjamin Deroche Date: Fri, 2 Aug 2024 11:00:27 +0200 Subject: [PATCH] Problem: Java Gradle scripts should use task configuration avoidance API Solution: Use it --- zproject_java.gsl | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/zproject_java.gsl b/zproject_java.gsl index 66578297..ec6af588 100644 --- a/zproject_java.gsl +++ b/zproject_java.gsl @@ -127,7 +127,7 @@ $(project.GENERATED_WARNING_HEADER:) */ buildscript { - configurations.all { + configurations.configureEach { resolutionStrategy { force 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' } @@ -207,7 +207,7 @@ dependencies { // ------------------------------------------------------------------ // Build section -task generateJniHeaders(type: Exec, dependsOn: 'classes') { +tasks.register('generateJniHeaders', type: Exec, dependsOn: 'classes') { def classpath = sourceSets.main.output.classesDirs def appclasspath = configurations.runtimeClasspath.files*.getAbsolutePath().join(File.pathSeparator) def nativeIncludes = 'src/native/include' @@ -222,14 +222,14 @@ task generateJniHeaders(type: Exec, dependsOn: 'classes') { commandLine("javac", "-h", "$nativeIncludes", "-classpath", "$classpath${File.pathSeparator}$appclasspath", *jniClasses, *utilityClasses) } -tasks.withType(Test) { +tasks.withType(Test).configureEach { def defaultJavaLibraryPath = System.getProperty("java.library.path") if (osdetector.os == 'windows') { - def extraJavaLibraryPath = hasNotEmptyProperty('buildPrefix') ? "$project.buildPrefix\\\\bin;$project.buildPrefix\\\\lib" : '' - extraJavaLibraryPath = extraJavaLibraryPath.replace("/", "\\\\") - systemProperty "java.library.path", "${projectDir}\\\\build\\\\Release${File.pathSeparator}" + - "${extraJavaLibraryPath}${File.pathSeparator}" + - "${defaultJavaLibraryPath}" + def extraJavaLibraryPath = hasNotEmptyProperty('buildPrefix') ? "$project.buildPrefix\\\\bin;$project.buildPrefix\\\\lib" : '' + extraJavaLibraryPath = extraJavaLibraryPath.replace("/", "\\\\") + systemProperty "java.library.path", "${projectDir}\\\\build\\\\Release${File.pathSeparator}" + + "${extraJavaLibraryPath}${File.pathSeparator}" + + "${defaultJavaLibraryPath}" } else { def extraJavaLibraryPath = hasNotEmptyProperty('buildPrefix') ? "$project.buildPrefix/lib" : '' systemProperty "java.library.path", "${projectDir}/build${File.pathSeparator}" + @@ -240,22 +240,22 @@ tasks.withType(Test) { } } -task initCMake(type: Exec, dependsOn: 'generateJniHeaders') { - workingDir 'build' +tasks.register('initCMake', type: Exec, dependsOn: 'generateJniHeaders') { + workingDir 'build' def prefixPath = hasNotEmptyProperty('buildPrefix') ? "-DCMAKE_PREFIX_PATH=$project.buildPrefix" : '' commandLine 'cmake', "$prefixPath", '..' } -task buildNative(type: Exec, dependsOn: 'initCMake') { +tasks.register('buildNative', type: Exec, dependsOn: 'initCMake') { if (osdetector.os == 'windows') { commandLine 'cmake', - '--build', 'build', + '--build', 'build', '--config', 'Release', '--target', '$(project.linkname)jni', - '--', '-verbosity:Minimal', '-maxcpucount' + '--', '-verbosity:Minimal', '-maxcpucount' } else { commandLine 'cmake', - '--build', 'build' + '--build', 'build' } } @@ -265,12 +265,12 @@ test.dependsOn buildNative // ------------------------------------------------------------------ // Install and Publish section -task sourcesJar(type: Jar, dependsOn: 'classes') { +tasks.register('sourcesJar', type: Jar, dependsOn: 'classes') { archiveClassifier = 'sources' from sourceSets.main.allSource } -task javadocJar(type: Jar, dependsOn: 'javadoc') { +tasks.register('javadocJar', type: Jar, dependsOn: 'javadoc') { archiveClassifier = 'javadoc' from javadoc.destinationDir } @@ -307,7 +307,6 @@ artifactoryPublish { publications ('mavenJava') } - bintray { user = System.getenv('BINTRAY_USER') key = System.getenv('BINTRAY_KEY') @@ -397,7 +396,6 @@ artifactoryPublish { publications ('mavenJava') } - bintray { user = System.getenv('BINTRAY_USER') key = System.getenv('BINTRAY_KEY') @@ -439,7 +437,7 @@ dependencies { // ------------------------------------------------------------------ // Build section -task copyLibs(type: Copy) { +tasks.register('copyLibs', type: Copy) { def libraryPaths = [] if (project.hasProperty('buildPrefix')) { if (osdetector.os == 'windows') { @@ -450,7 +448,7 @@ task copyLibs(type: Copy) { } def javaLibraryPaths = System.getProperty('java.library.path').split(File.pathSeparator).toList() - libraryPaths.addAll (javaLibraryPaths) + libraryPaths.addAll(javaLibraryPaths) libraryPaths.add('/usr/local/lib') if (osdetector.os == 'windows') {