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'
}
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'
/**
@ -150,7 +139,7 @@ subprojects {
}
configurations {
all {
configureEach {
resolutionStrategy {
force "commons-io:commons-io:${commonsIoVersion}"
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.compilerArgs += '-Xlint:unchecked'
options.deprecation = true
options.incremental = true
}
tasks.withType(Test) {
tasks.withType(Test).configureEach {
systemProperty "file.encoding", "UTF-8"
}
tasks.withType(Javadoc) {
tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}
tasks.withType(AbstractArchiveTask).configureEach {
@ -227,13 +216,13 @@ subprojects {
// helper-target to get a directory with all third-party libraries
// this is used for mass-regression-testing
task getDeps(type: Copy) {
tasks.register('getDeps', Copy) {
from sourceSets.main.runtimeClasspath
into 'build/runtime/'
}
tasks.withType(Jar) {
duplicatesStrategy = 'fail'
tasks.withType(Jar).configureEach {
duplicatesStrategy = DuplicatesStrategy.FAIL
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
doLast {
@ -375,10 +364,10 @@ subprojects {
]
// detect if running on Jenkins/CI
isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD"));
isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD"))
if (isCIBuild) {
System.out.println("Run with reduced parallelism for CI build");
System.out.println("Run with reduced parallelism for CI build")
jvmArgs += [
// Strictly serial
@ -597,7 +586,7 @@ subprojects {
generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"
tasks.withType(GenerateModuleMetadata) {
tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false
}
@ -625,14 +614,14 @@ subprojects {
}
// initial try to provide a combined JavaDoc, grouping is still missing here, though!
task allJavaDoc(type: Javadoc) {
var prj = [ project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad') ]
tasks.register('allJavaDoc', Javadoc) {
var prj = [project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad')]
source prj.collect { it.sourceSets.main.allJava }
// for possible settings see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
maxMemory="2048M"
maxMemory = "2048M"
// for possible options see https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
options.use = true
@ -753,13 +742,13 @@ task jenkinsLite(dependsOn: [
//compileJava.dependsOn 'downloadJarsToLibs'
task replaceVersion() {
tasks.register('replaceVersion') {
outputs.upToDateWhen { false }
var version = subprojects[0].version
var tokens = [
[ 'osgi', 'pom.xml', '(packaging>\\n\\s*<version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}" ],
[ 'osgi', 'pom.xml', '(<poi.version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}" ]
['osgi', 'pom.xml', '(packaging>\\n\\s*<version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}"],
['osgi', 'pom.xml', '(<poi.version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}"]
// [ '.', 'build.gradle', ' version = \'[0-9.]+(?:-SNAPSHOT)?\'', " version = '${version}'" ]
]
@ -784,7 +773,7 @@ task zipJavadocs(type: Zip, dependsOn: allJavaDoc) {
archiveExtension = 'jar'
}
tasks.withType(Tar) {
tasks.withType(Tar).configureEach {
compression = Compression.GZIP
archiveExtension = 'tgz'
}
@ -843,7 +832,7 @@ distributions {
}
}
task soLinkCheck() {
tasks.register('soLinkCheck') {
doLast {
def path = ant.path {
fileset(dir: '.', includes: '**/*.java') {
@ -887,7 +876,7 @@ srcDistZip.dependsOn srcDep
soLinkCheck.dependsOn srcDep
rat.dependsOn soLinkCheck
task fixDistDir {
tasks.register('fixDistDir') {
doLast {
ant.mkdir(dir: '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 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'
javaCompiler = javaToolchains.compilerFor {

View File

@ -34,10 +34,10 @@ sourceSets {
}
// Run out read demo by default
tasks.withType(JavaExec) {
tasks.withType(JavaExec).configureEach {
classpath = sourceSets.main.runtimeClasspath
}
task runScript(type: JavaExec) {
tasks.register('runScript', JavaExec) {
mainClass = "SpreadSheetDemo"
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_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'
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'
javaCompiler = javaToolchains.compilerFor {
@ -123,7 +123,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ] ) {
setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
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_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'
javaCompiler = javaToolchains.compilerFor {
@ -123,7 +123,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ] ) {
setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output

View File

@ -54,7 +54,7 @@ compileJava {
options.forkOptions.jvmArgs += '-Xmx2G'
}
task compileJava9(type: JavaCompile) {
tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava'
javaCompiler = javaToolchains.compilerFor {
@ -71,19 +71,19 @@ task compileJava9(type: JavaCompile) {
]
}
task copy_xsds(type: Copy) {
from ('src/main/xmlschema/org/apache/poi/xdgf')
from ('src/main/xmlschema/org/apache/poi/schemas') {
tasks.register('copy_xsds', Copy) {
from('src/main/xmlschema/org/apache/poi/xdgf')
from('src/main/xmlschema/org/apache/poi/schemas') {
include 'XAdES*.xsd', '*.xsdconfig', 'xmldsig*.xsd', 'ooxmlSchemas.xsdconfig', 'markup-compatibility.xsd',
'vmlDrawing.xsd', 'word10.xsd', 'word12.xsd', 'xlThreaded*.xsd', 'dml-drawing.xsd', 'drawing-chart2012.xsd',
'chartEx.xsd'
exclude '*.zip'
}
from ('src/main/xmlschema/org/apache/poi/poifs/crypt') {
from('src/main/xmlschema/org/apache/poi/poifs/crypt') {
include 'signatureInfo.xsd'
}
from (zipTree('src/main/xmlschema/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip'))
from (zipTree('src/main/xmlschema/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip')) {
from(zipTree('src/main/xmlschema/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip'))
from(zipTree('src/main/xmlschema/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip')) {
include 'opc-digSig.xsd', 'opc-relationships.xsd'
}
into 'build/xsds'
@ -126,7 +126,7 @@ task generate_beans(dependsOn: copy_xsds) {
}
}
task sourceJar(type: Jar) {
tasks.register('sourceJar', Jar) {
setArchiveClassifier 'sources'
from sourceSets.main.allJava
}

View File

@ -36,7 +36,7 @@ java {
}
}
task compileJava9(type: JavaCompile) {
tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava'
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 String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
task generateModuleInfo() {
tasks.register('generateModuleInfo') {
File fileIn = file("${OOXML_LITE_REPORT}.clazz")
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'
// 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
// duplicatesStrategy = 'exclude'
// duplicatesStrategy = DuplicatesStrategy.EXCLUDE
includeEmptyDirs = false
manifest {

View File

@ -149,7 +149,7 @@ compileJava {
dependsOn 'fixBatik', 'cleanupBatik'
}
task compileJava9(type: JavaCompile) {
tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi:jar'
javaCompiler = javaToolchains.compilerFor {
@ -166,7 +166,7 @@ task compileJava9(type: JavaCompile) {
]
}
task compileTest9(type: JavaCompile) {
tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi:testJar'
javaCompiler = javaToolchains.compilerFor {
@ -199,7 +199,7 @@ task testJar(type: Jar, dependsOn: testClasses) {
setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output
@ -209,17 +209,17 @@ task testJar(type: Jar, dependsOn: testClasses) {
}
// based on https://github.com/moditect/moditect-gradle-plugin/issues/12
task fixBatik(type: Zip) {
tasks.register('fixBatik', Zip) {
ant.mkdir(dir: "${buildDir}/brokenJars")
archiveFileName = "batik-script-${batikVersion}.jar"
destinationDirectory = file("${buildDir}/brokenJars")
from zipTree(configurations.broken.files.find{ f -> f.name.startsWith("batik-script") })
from zipTree(configurations.broken.files.find { f -> f.name.startsWith("batik-script") })
filesMatching("**/org.apache.batik.script.InterpreterFactory") {
it.filter{ it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
it.filter { it2 -> it2.contains("Rhino") ? "#" + it2 : it2 }
}
}
task cleanupBatik(type: Delete) {
tasks.register('cleanupBatik', Delete) {
// remove older files to avoid build failures because of duplicate modules
delete fileTree("${buildDir}/brokenJars/").matching {
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 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'
javaCompiler = javaToolchains.compilerFor {
@ -70,7 +70,7 @@ task compileJava9(type: JavaCompile) {
]
}
task compileTest9(type: JavaCompile) {
tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi:jar'
javaCompiler = javaToolchains.compilerFor {
@ -103,7 +103,7 @@ task testJar(type: Jar, dependsOn: testClasses) {
setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.test.output + sourceSets.main.output

View File

@ -56,7 +56,7 @@ dependencies {
}
// generate and compile the file Version.java file
task generateVersionJava() {
tasks.register('generateVersionJava') {
//dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build'
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 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'
javaCompiler = javaToolchains.compilerFor {
@ -97,7 +97,7 @@ task compileJava9(type: JavaCompile) {
]
}
task compileTest9(type: JavaCompile) {
tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava'
javaCompiler = javaToolchains.compilerFor {
@ -129,7 +129,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ]) {
setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
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.
// 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.
task bootstrapWrapper() {
tasks.register('bootstrapWrapper') {
// In the doLast block so this runs when the task is called and not during project configuration.
doLast {
def wrapperBasePath = "\$APP_HOME/gradle/wrapper"
@ -79,7 +79,7 @@ task bootstrapWrapper() {
wrapper.finalizedBy bootstrapWrapper
// 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"
}
wrapper.finalizedBy removeWindowsScript