Some changes to the Gradle build

Apply IDE suggestions for Gradle build files
Remove obsolete sorting of gradle-wrapper.properties

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923284 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2025-01-20 20:05:58 +00:00
parent 045a37f9c1
commit 1dbcea46d5
12 changed files with 113 additions and 124 deletions

View File

@ -80,17 +80,6 @@ wrapper {
gradleVersion = '8.12' gradleVersion = '8.12'
} }
task adjustWrapperPropertiesFile {
doLast {
ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) {
fileset(dir: project.projectDir, includes: 'gradle/wrapper/gradle-wrapper.properties')
}
new File(project.projectDir, 'gradle/wrapper/gradle-wrapper.properties').with { it.text = it.readLines().findAll { it }.sort().join('\n') }
ant.fixcrlf(file: 'gradle/wrapper/gradle-wrapper.properties', eol: 'lf')
}
}
wrapper.finalizedBy adjustWrapperPropertiesFile
group = 'org.apache.poi' group = 'org.apache.poi'
/** /**
@ -150,7 +139,7 @@ subprojects {
} }
configurations { configurations {
all { configureEach {
resolutionStrategy { resolutionStrategy {
force "commons-io:commons-io:${commonsIoVersion}" force "commons-io:commons-io:${commonsIoVersion}"
force 'org.slf4j:slf4j-api:2.0.16' force 'org.slf4j:slf4j-api:2.0.16'
@ -159,16 +148,16 @@ subprojects {
} }
} }
tasks.withType(JavaCompile) { tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
options.compilerArgs += '-Xlint:unchecked' options.compilerArgs += '-Xlint:unchecked'
options.deprecation = true options.deprecation = true
options.incremental = true options.incremental = true
} }
tasks.withType(Test) { tasks.withType(Test).configureEach {
systemProperty "file.encoding", "UTF-8" systemProperty "file.encoding", "UTF-8"
} }
tasks.withType(Javadoc) { tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
} }
tasks.withType(AbstractArchiveTask).configureEach { tasks.withType(AbstractArchiveTask).configureEach {
@ -227,13 +216,13 @@ subprojects {
// helper-target to get a directory with all third-party libraries // helper-target to get a directory with all third-party libraries
// this is used for mass-regression-testing // this is used for mass-regression-testing
task getDeps(type: Copy) { tasks.register('getDeps', Copy) {
from sourceSets.main.runtimeClasspath from sourceSets.main.runtimeClasspath
into 'build/runtime/' into 'build/runtime/'
} }
tasks.withType(Jar) { tasks.withType(Jar).configureEach {
duplicatesStrategy = 'fail' duplicatesStrategy = DuplicatesStrategy.FAIL
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
doLast { doLast {
@ -375,10 +364,10 @@ subprojects {
] ]
// detect if running on Jenkins/CI // detect if running on Jenkins/CI
isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD")); isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD"))
if (isCIBuild) { if (isCIBuild) {
System.out.println("Run with reduced parallelism for CI build"); System.out.println("Run with reduced parallelism for CI build")
jvmArgs += [ jvmArgs += [
// Strictly serial // Strictly serial
@ -597,7 +586,7 @@ subprojects {
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom" generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"
tasks.withType(GenerateModuleMetadata) { tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false enabled = false
} }
@ -625,7 +614,7 @@ subprojects {
} }
// initial try to provide a combined JavaDoc, grouping is still missing here, though! // initial try to provide a combined JavaDoc, grouping is still missing here, though!
task allJavaDoc(type: Javadoc) { tasks.register('allJavaDoc', Javadoc) {
var prj = [project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad')] var prj = [project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad')]
source prj.collect { it.sourceSets.main.allJava } source prj.collect { it.sourceSets.main.allJava }
@ -753,7 +742,7 @@ task jenkinsLite(dependsOn: [
//compileJava.dependsOn 'downloadJarsToLibs' //compileJava.dependsOn 'downloadJarsToLibs'
task replaceVersion() { tasks.register('replaceVersion') {
outputs.upToDateWhen { false } outputs.upToDateWhen { false }
var version = subprojects[0].version var version = subprojects[0].version
@ -784,7 +773,7 @@ task zipJavadocs(type: Zip, dependsOn: allJavaDoc) {
archiveExtension = 'jar' archiveExtension = 'jar'
} }
tasks.withType(Tar) { tasks.withType(Tar).configureEach {
compression = Compression.GZIP compression = Compression.GZIP
archiveExtension = 'tgz' archiveExtension = 'tgz'
} }
@ -843,7 +832,7 @@ distributions {
} }
} }
task soLinkCheck() { tasks.register('soLinkCheck') {
doLast { doLast {
def path = ant.path { def path = ant.path {
fileset(dir: '.', includes: '**/*.java') { fileset(dir: '.', includes: '**/*.java') {
@ -887,7 +876,7 @@ srcDistZip.dependsOn srcDep
soLinkCheck.dependsOn srcDep soLinkCheck.dependsOn srcDep
rat.dependsOn soLinkCheck rat.dependsOn soLinkCheck
task fixDistDir { tasks.register('fixDistDir') {
doLast { doLast {
ant.mkdir(dir: 'build/dist') ant.mkdir(dir: 'build/dist')
ant.move(todir: 'build/dist') { ant.move(todir: 'build/dist') {

View File

@ -49,7 +49,7 @@ final String MODULE_NAME = 'org.apache.poi.examples'
final Pattern MODULE_REGEX = ~'\\.jar$' final Pattern MODULE_REGEX = ~'\\.jar$'
final List MODULE_COMPILE_PATH = sourceSets.main.compileClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique() final List MODULE_COMPILE_PATH = sourceSets.main.compileClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar' dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {

View File

@ -34,10 +34,10 @@ sourceSets {
} }
// Run out read demo by default // Run out read demo by default
tasks.withType(JavaExec) { tasks.withType(JavaExec).configureEach {
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
} }
task runScript(type: JavaExec) { tasks.register('runScript', JavaExec) {
mainClass = "SpreadSheetDemo" mainClass = "SpreadSheetDemo"
args = ["../../../../test-data/spreadsheet/Simple.xls"] args = ["../../../../test-data/spreadsheet/Simple.xls"]
} }

View File

@ -57,7 +57,7 @@ final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-oo
final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report' final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)" final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar' dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -74,7 +74,7 @@ task compileJava9(type: JavaCompile) {
] ]
} }
task compileTest9(type: JavaCompile) { tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi-ooxml:jar', ':poi-scratchpad:jar' dependsOn 'compileTestJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -123,7 +123,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ] ) {
setArchiveClassifier 'tests' setArchiveClassifier 'tests'
// ignore second module-info.class from main // ignore second module-info.class from main
duplicatesStrategy = 'exclude' duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output from sourceSets.test.output + sourceSets.main.output

View File

@ -90,7 +90,7 @@ final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-oo
final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report' final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)" final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
task compileTest9(type: JavaCompile) { tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi-ooxml:testJar', ':poi-scratchpad:testJar', ':poi-examples:jar' dependsOn 'compileTestJava', ':poi-ooxml:testJar', ':poi-scratchpad:testJar', ':poi-examples:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -123,7 +123,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ] ) {
setArchiveClassifier 'tests' setArchiveClassifier 'tests'
// ignore second module-info.class from main // ignore second module-info.class from main
duplicatesStrategy = 'exclude' duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output from sourceSets.test.output + sourceSets.main.output

View File

@ -54,7 +54,7 @@ compileJava {
options.forkOptions.jvmArgs += '-Xmx2G' options.forkOptions.jvmArgs += '-Xmx2G'
} }
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava' dependsOn 'compileJava'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -71,7 +71,7 @@ task compileJava9(type: JavaCompile) {
] ]
} }
task copy_xsds(type: Copy) { tasks.register('copy_xsds', Copy) {
from('src/main/xmlschema/org/apache/poi/xdgf') from('src/main/xmlschema/org/apache/poi/xdgf')
from('src/main/xmlschema/org/apache/poi/schemas') { from('src/main/xmlschema/org/apache/poi/schemas') {
include 'XAdES*.xsd', '*.xsdconfig', 'xmldsig*.xsd', 'ooxmlSchemas.xsdconfig', 'markup-compatibility.xsd', include 'XAdES*.xsd', '*.xsdconfig', 'xmldsig*.xsd', 'ooxmlSchemas.xsdconfig', 'markup-compatibility.xsd',
@ -126,7 +126,7 @@ task generate_beans(dependsOn: copy_xsds) {
} }
} }
task sourceJar(type: Jar) { tasks.register('sourceJar', Jar) {
setArchiveClassifier 'sources' setArchiveClassifier 'sources'
from sourceSets.main.allJava from sourceSets.main.allJava
} }

View File

@ -36,7 +36,7 @@ java {
} }
} }
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava' dependsOn 'compileJava'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {

View File

@ -43,7 +43,7 @@ final Pattern MODULE_REGEX = ~'\\.jar$'
final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique() final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report' final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
task generateModuleInfo() { tasks.register('generateModuleInfo') {
File fileIn = file("${OOXML_LITE_REPORT}.clazz") File fileIn = file("${OOXML_LITE_REPORT}.clazz")
File fileOut = file("src/main/java9/module-info.java") File fileOut = file("src/main/java9/module-info.java")
@ -65,7 +65,7 @@ task generateModuleInfo() {
} }
} }
task compileOoxmlLite(type: Copy) { tasks.register('compileOoxmlLite', Copy) {
dependsOn 'generateModuleInfo', ':poi-ooxml-full:generate_beans', ':poi-ooxml-full:compileJava' dependsOn 'generateModuleInfo', ':poi-ooxml-full:generate_beans', ':poi-ooxml-full:compileJava'
// This task is currently always executed, because gradle thinks files with two dollar signs // This task is currently always executed, because gradle thinks files with two dollar signs
@ -124,7 +124,7 @@ jar {
} }
// ignore second module-info.class from poi-ooxml-full // ignore second module-info.class from poi-ooxml-full
// duplicatesStrategy = 'exclude' // duplicatesStrategy = DuplicatesStrategy.EXCLUDE
includeEmptyDirs = false includeEmptyDirs = false
manifest { manifest {

View File

@ -149,7 +149,7 @@ compileJava {
dependsOn 'fixBatik', 'cleanupBatik' dependsOn 'fixBatik', 'cleanupBatik'
} }
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi:jar' dependsOn 'compileJava', ':poi:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -166,7 +166,7 @@ task compileJava9(type: JavaCompile) {
] ]
} }
task compileTest9(type: JavaCompile) { tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi:testJar' dependsOn 'compileTestJava', ':poi:testJar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -199,7 +199,7 @@ task testJar(type: Jar, dependsOn: testClasses) {
setArchiveClassifier 'tests' setArchiveClassifier 'tests'
// ignore second module-info.class from main // ignore second module-info.class from main
duplicatesStrategy = 'exclude' duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output from sourceSets.test.output + sourceSets.main.output
@ -209,7 +209,7 @@ task testJar(type: Jar, dependsOn: testClasses) {
} }
// based on https://github.com/moditect/moditect-gradle-plugin/issues/12 // based on https://github.com/moditect/moditect-gradle-plugin/issues/12
task fixBatik(type: Zip) { tasks.register('fixBatik', Zip) {
ant.mkdir(dir: "${buildDir}/brokenJars") ant.mkdir(dir: "${buildDir}/brokenJars")
archiveFileName = "batik-script-${batikVersion}.jar" archiveFileName = "batik-script-${batikVersion}.jar"
destinationDirectory = file("${buildDir}/brokenJars") destinationDirectory = file("${buildDir}/brokenJars")
@ -219,7 +219,7 @@ task fixBatik(type: Zip) {
} }
} }
task cleanupBatik(type: Delete) { tasks.register('cleanupBatik', Delete) {
// remove older files to avoid build failures because of duplicate modules // remove older files to avoid build failures because of duplicate modules
delete fileTree("${buildDir}/brokenJars/").matching { delete fileTree("${buildDir}/brokenJars/").matching {
include "*.jar" include "*.jar"

View File

@ -53,7 +53,7 @@ final Pattern MODULE_REGEX = ~'\\.jar$'
final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique() final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique() final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi:jar' dependsOn 'compileJava', ':poi:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -70,7 +70,7 @@ task compileJava9(type: JavaCompile) {
] ]
} }
task compileTest9(type: JavaCompile) { tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi:jar' dependsOn 'compileTestJava', ':poi:jar'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -103,7 +103,7 @@ task testJar(type: Jar, dependsOn: testClasses) {
setArchiveClassifier 'tests' setArchiveClassifier 'tests'
// ignore second module-info.class from main // ignore second module-info.class from main
duplicatesStrategy = 'exclude' duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output from sourceSets.test.output + sourceSets.main.output

View File

@ -56,7 +56,7 @@ dependencies {
} }
// generate and compile the file Version.java file // generate and compile the file Version.java file
task generateVersionJava() { tasks.register('generateVersionJava') {
//dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build' //dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build'
File fileIn = file("src/main/version/Version.java.template") File fileIn = file("src/main/version/Version.java.template")
@ -80,7 +80,7 @@ final Pattern MODULE_NOT_REGEX = ~'(poi[/\\\\][^/\\\\]+$|batik-script)'
final Pattern MODULE_REGEX = ~'\\.jar$' final Pattern MODULE_REGEX = ~'\\.jar$'
final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique() final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
task compileJava9(type: JavaCompile) { tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava' dependsOn 'compileJava'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -97,7 +97,7 @@ task compileJava9(type: JavaCompile) {
] ]
} }
task compileTest9(type: JavaCompile) { tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava' dependsOn 'compileTestJava'
javaCompiler = javaToolchains.compilerFor { javaCompiler = javaToolchains.compilerFor {
@ -129,7 +129,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ]) {
setArchiveClassifier 'tests' setArchiveClassifier 'tests'
// ignore second module-info.class from main // ignore second module-info.class from main
duplicatesStrategy = 'exclude' duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output from sourceSets.test.output + sourceSets.main.output

View File

@ -30,7 +30,7 @@ wrapper {
// Custom task to inject support for downloading the gradle wrapper jar if it doesn't exist. // Custom task to inject support for downloading the gradle wrapper jar if it doesn't exist.
// This allows us to avoid checking in the jar to our repository. // This allows us to avoid checking in the jar to our repository.
// Additionally adds a license header to the wrapper while editing the file contents. // Additionally adds a license header to the wrapper while editing the file contents.
task bootstrapWrapper() { tasks.register('bootstrapWrapper') {
// In the doLast block so this runs when the task is called and not during project configuration. // In the doLast block so this runs when the task is called and not during project configuration.
doLast { doLast {
def wrapperBasePath = "\$APP_HOME/gradle/wrapper" def wrapperBasePath = "\$APP_HOME/gradle/wrapper"
@ -79,7 +79,7 @@ task bootstrapWrapper() {
wrapper.finalizedBy bootstrapWrapper wrapper.finalizedBy bootstrapWrapper
// Remove the generated batch file since we don't test building in the Windows environment. // Remove the generated batch file since we don't test building in the Windows environment.
task removeWindowsScript(type: Delete) { tasks.register('removeWindowsScript', Delete) {
delete "$rootDir/gradlew.bat" delete "$rootDir/gradlew.bat"
} }
wrapper.finalizedBy removeWindowsScript wrapper.finalizedBy removeWindowsScript