diff --git a/build.gradle b/build.gradle index 7c33d5ee829..75b7dba2095 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,8 @@ */ defaultTasks = ["sdk"] +import com.sun.javafx.gradle.CompileTarget + import java.nio.file.Files import java.nio.file.StandardCopyOption import java.time.Instant @@ -165,16 +167,6 @@ void loadProperties(String sourceFileName) { } } -/** - * Struct used to contain some information passed to the closure - * passed to compileTargets. - */ -class CompileTarget { - String name; - String upper; - String capital; -} - /** * Iterates over each of the compile targets, passing the given closure * a CompileTarget instance. @@ -342,8 +334,6 @@ ext.IS_MAC = OS_NAME.contains("mac") || OS_NAME.contains("darwin") ext.IS_WINDOWS = OS_NAME.contains("windows") ext.IS_LINUX = OS_NAME.contains("linux") -ext.MAVEN_GROUP_ID = "org.openjfx" - // Enable native access from modules with native code ext.enableNativeGraphics='--enable-native-access=javafx.graphics' ext.enableNativeAll='--enable-native-access=javafx.graphics,javafx.media,javafx.web' @@ -526,10 +516,6 @@ ext.IS_DEBUG_JAVA = CONF == "Debug" || CONF == "DebugNative" ext.IS_DEBUG_NATIVE = CONF == "DebugNative" ext.IS_RELEASE = !ext.IS_DEBUG_JAVA -// Specifies whether to enable the Maven publishing tasks -defineProperty("MAVEN_PUBLISH", "false") -ext.IS_MAVEN_PUBLISH = Boolean.parseBoolean(MAVEN_PUBLISH) - // Define the compiler lint warnings to enable. // // We define a separate set of options for normal classes, test classes @@ -697,7 +683,6 @@ if (HUDSON_JOB_NAME == "not_hudson") { defineProperty("RELEASE_SUFFIX", relSuffix) defineProperty("RELEASE_VERSION_SHORT", "${RELEASE_VERSION}${RELEASE_SUFFIX}") defineProperty("RELEASE_VERSION_LONG", "${RELEASE_VERSION_SHORT}+${PROMOTED_BUILD_NUMBER}${relOpt}") -defineProperty("MAVEN_VERSION", IS_MAVEN_PUBLISH ? (IS_MILESTONE_FCS ? "${RELEASE_VERSION_SHORT}" : "${RELEASE_VERSION_LONG}") : "") // Check whether the COMPILE_TARGETS property has been specified (if so, it was done by // the user and not by this script). If it has not been defined then default @@ -816,7 +801,6 @@ try { // build / test a standalone sdk for running with a JDK that does not include // the javafx modules. - /** * Fetch/Check that external tools are present for the build. This method * will conditionally download the packages from project defined ivy repositories @@ -1549,8 +1533,6 @@ logger.quiet("RELEASE_SUFFIX: $RELEASE_SUFFIX") logger.quiet("RELEASE_VERSION_SHORT: $RELEASE_VERSION_SHORT") logger.quiet("RELEASE_VERSION_LONG: $RELEASE_VERSION_LONG") logger.quiet("RELEASE_VERSION_PADDED: $RELEASE_VERSION_PADDED") -logger.quiet("MAVEN_PUBLISH: $MAVEN_PUBLISH") -logger.quiet("MAVEN_VERSION: $MAVEN_VERSION") logger.quiet("UPDATE_STUB_CACHE: $UPDATE_STUB_CACHE") /****************************************************************************** @@ -1769,113 +1751,6 @@ void addJSL(Project project, String name, String pkg, List addExports, C } -void addMavenPublication(Project project, List projectDependencies) { - if (!IS_MAVEN_PUBLISH) { - return - } - - if (!project.hasProperty("moduleName")) { - fail("Project ${project} has no module name") - } - projectDependencies.each { projName -> - def dep = project.project(":$projName") - if (!dep.hasProperty("moduleName")) { - fail("${project} dependency ${dep} has no module name") - } - } - - project.apply plugin: 'maven-publish' - - project.group = MAVEN_GROUP_ID - project.version = MAVEN_VERSION - - if (project.name == 'base') { - project.publishing { - publications { - javafx(MavenPublication) { - artifactId = 'javafx' - artifacts = [] - } - } - } - } - - gradle.taskGraph.whenReady { g -> - project.tasks.findAll { it.name == 'generatePomFileForJavafxPublication'}.each { it -> - it.doLast { - copy { - into project.file("${project.buildDir}/publications/javafx") - from file("${rootProject.projectDir}/javafx.pom") - rename "javafx.pom", "pom-default.xml" - filter { line -> - line.replaceAll("@VERSION@", MAVEN_VERSION) - } - } - } - } - } - - project.publishing { - repositories { - maven { - def repositoryUrl = project.hasProperty('repositoryUrl') ? project.getProperty('repositoryUrl') : "" - def repositoryUsername = project.hasProperty('repositoryUsername') ? project.getProperty('repositoryUsername') : "" - def repositoryPassword = project.hasProperty('repositoryPassword') ? project.getProperty('repositoryPassword') : "" - url repositoryUrl - credentials { - username repositoryUsername - password repositoryPassword - } - } - } - } - - compileTargets { t -> - project.publishing { - publications { - maven(MavenPublication) { - def artifactName = project.moduleName.replace('.', '-') - artifactId = artifactName - - afterEvaluate { - artifact project.tasks."moduleEmptyPublicationJar$t.capital" - artifact project.tasks."modularPublicationJar$t.capital" { - archiveClassifier.set("$t.name") - } - } - - pom.withXml { - Node parent = asNode().appendNode("parent") - parent.appendNode("groupId", MAVEN_GROUP_ID) - parent.appendNode("artifactId", "javafx") - parent.appendNode("version", MAVEN_VERSION) - - Node dependencies = asNode().appendNode("dependencies") - - Node projectDependencyPlatform = dependencies.appendNode("dependency") - projectDependencyPlatform.appendNode("groupId", MAVEN_GROUP_ID) - projectDependencyPlatform.appendNode("artifactId", artifactName) - projectDependencyPlatform.appendNode("version", MAVEN_VERSION) - projectDependencyPlatform.appendNode("classifier", "\${javafx.platform}") - - if (!projectDependencies.empty) { - projectDependencies.each { projName -> - def dep = project.project(":$projName") - def depName = dep.moduleName.replace('.', '-') - Node projectDependency = dependencies.appendNode("dependency") - projectDependency.appendNode("groupId", MAVEN_GROUP_ID) - projectDependency.appendNode("artifactId", depName) - projectDependency.appendNode("version", MAVEN_VERSION) - } - } - } - } - } - - } - } -} - /** * Verifies that all of the *.java files in a source tree have the * correct package name. If not, fail the build. @@ -2294,7 +2169,6 @@ project(":base") { sourceSets.main.java.srcDirs += "$buildDir/gensrc/java" compileJava.dependsOn processVersionInfo - addMavenPublication(project, []) addValidateSourceSets(project, sourceSets) @@ -2892,8 +2766,6 @@ project(":graphics") { } } - addMavenPublication(project, [ 'base' ]) - addValidateSourceSets(project, sourceSets) } @@ -2970,8 +2842,6 @@ project(":controls") { } processShimsResources.dependsOn(copyShimBssTask) - addMavenPublication(project, [ 'graphics' ]) - addValidateSourceSets(project, sourceSets) } @@ -3040,8 +2910,6 @@ project(":incubator.input") { modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.graphics/build/classes/java/main" modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.base/build/classes/java/main" - addMavenPublication(project, [ 'controls' ]) - addValidateSourceSets(project, sourceSets) } @@ -3099,8 +2967,6 @@ project(":incubator.richtext") { modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.graphics/build/classes/java/main" modulePath += File.pathSeparator + "${rootProject.projectDir}/modules/javafx.base/build/classes/java/main" - addMavenPublication(project, [ 'controls', 'incubator.input' ]) - addValidateSourceSets(project, sourceSets) } @@ -3158,10 +3024,6 @@ project(":swing") { jvmArgs enableNativeGraphics } - if (COMPILE_SWING) { - addMavenPublication(project, [ 'graphics' ]) - } - addValidateSourceSets(project, sourceSets) } @@ -3279,7 +3141,6 @@ project(":fxml") { classpath += files("$JDK_HOME/jre/lib/ext/nashorn.jar") } - addMavenPublication(project, [ 'controls' ]) addValidateSourceSets(project, sourceSets) } @@ -3887,7 +3748,6 @@ project(":media") { } } - addMavenPublication(project, [ 'graphics' ]) addValidateSourceSets(project, sourceSets) } @@ -3911,8 +3771,6 @@ project(":jsobject") { dependencies { } - addMavenPublication(project, []) - addValidateSourceSets(project, sourceSets) } @@ -4215,8 +4073,6 @@ project(":web") { assemble.dependsOn compileJavaDOMBinding, drtJar } - addMavenPublication(project, [ 'controls', 'media', 'jsobject' ]) - addValidateSourceSets(project, sourceSets) } @@ -4474,6 +4330,10 @@ project(":systemTests") { addValidateSourceSets(project, nonModSrcSets, modSrcSets) } +// Apply Maven Publishing to all projects (if enabled). +// Need to be done after all projects were defined that should be published. +apply from: 'maven-publish.gradle' + void setupLintOptions(Task compile, String lintOpts, String extraLintOpts) { lintOpts.split("[, ]").each { s -> compile.options.compilerArgs += "-Xlint:$s" @@ -5325,6 +5185,10 @@ compileTargets { t -> } buildModules.dependsOn(buildModulesTask) + // Configures the maven publication (if enabled) for all projects of this compile target. + // Will run after the buildModulesTask. + configureMavenPublication(moduleProjList, t, buildModulesTask) + // BUNDLED SDK moduleProjList.each { project -> // Copy classes, bin, and lib directories @@ -5513,46 +5377,6 @@ compileTargets { t -> } buildModules.dependsOn(zipSourceFilesTask) - // ============================================================ - - // Maven Publications - def publicationDirName = "${platformPrefix}publications" - def publicationDir = "${rootProject.buildDir}/${publicationDirName}" - - moduleProjList.each { project -> - // Create publications to be uploaded - - def moduleName = project.ext.moduleName - def buildDir = project.buildDir - - def dstModularJarDir="${publicationDir}" - def srcClassesDir = "${buildDir}/${platformPrefix}module-classes" - def srcLibsDir = "${buildDir}/${platformPrefix}module-lib" - - def modularEmptyPublicationJarName = "${moduleName}.jar" - def modularEmptyPublicationJarTask = project.task("moduleEmptyPublicationJar${t.capital}", type: Jar) { - destinationDirectory = file("${dstModularJarDir}") - archiveFileName = modularEmptyPublicationJarName - manifest { - attributes( - 'Automatic-Module-Name':"${moduleName}Empty" - ) - } - } - - def modularPublicationJarName = "${moduleName}-${t.name}.jar" - def modularPublicationJarTask = project.task("modularPublicationJar${t.capital}", type: Jar, dependsOn: modularEmptyPublicationJarTask) { - destinationDirectory = file("${dstModularJarDir}") - archiveFileName = modularPublicationJarName - from srcLibsDir - from srcClassesDir - } - - buildModulesTask.dependsOn(modularPublicationJarTask) - - } - // ============================================================ - def buildRunArgsTask = task("buildRunArgs$t.capital", group: "Build", dependsOn: buildModulesTask) { outputs.file(runArgsFile); @@ -5700,9 +5524,6 @@ compileTargets { t -> if (project.tasks.getByName("copyClassFiles$t.capital") != null) { project.tasks.getByName("copyClassFiles$t.capital").dependsOn(buildModuleClassesTask) } - if (project.tasks.getByName("modularPublicationJar$t.capital") != null) { - project.tasks.getByName("modularPublicationJar$t.capital").dependsOn(buildModuleClassesTask) - } } def buildModuleLibsTask = task("buildModuleLibs$t.capital") { @@ -5772,7 +5593,6 @@ compileTargets { t -> } baseProject.tasks.getByName("copyLibFilesStandalone$t.capital").dependsOn(buildModuleBaseTask) baseProject.tasks.getByName("copyLibFiles$t.capital").dependsOn(buildModuleBaseTask) - baseProject.tasks.getByName("modularPublicationJar$t.capital").dependsOn(buildModuleBaseTask) def buildModuleGraphicsTask = task("buildModuleGraphics$t.capital", type: Copy, dependsOn: graphicsProject.assemble) { group = "Basic" @@ -5847,7 +5667,6 @@ compileTargets { t -> graphicsProject.tasks.getByName("copyNativeFilesStandalone$t.capital").dependsOn(buildModuleGraphicsTask) graphicsProject.tasks.getByName("copyLibFilesStandalone$t.capital").dependsOn(buildModuleGraphicsTask) graphicsProject.tasks.getByName("copyLibFiles$t.capital").dependsOn(buildModuleGraphicsTask) - graphicsProject.tasks.getByName("modularPublicationJar$t.capital").dependsOn(buildModuleGraphicsTask) def buildModuleMediaTask = task("buildModuleMedia$t.capital", type: Copy, dependsOn: [mediaProject.assemble, prepOpenJfxStubs]) { group = "Basic" @@ -5922,7 +5741,6 @@ compileTargets { t -> mediaProject.tasks.getByName("copyNativeFilesStandalone$t.capital").dependsOn(buildModuleMediaTask) mediaProject.tasks.getByName("copyLibFilesStandalone$t.capital").dependsOn(buildModuleMediaTask) mediaProject.tasks.getByName("copyLibFiles$t.capital").dependsOn(buildModuleMediaTask) - mediaProject.tasks.getByName("modularPublicationJar$t.capital").dependsOn(buildModuleMediaTask) def buildModuleWeb = task("buildModuleWeb$t.capital", type: Copy, dependsOn: [webProject.assemble, prepOpenJfxStubs]) { group = "Basic" @@ -5975,7 +5793,6 @@ compileTargets { t -> webProject.tasks.getByName("copyNativeFilesStandalone$t.capital").dependsOn(buildModuleWeb) webProject.tasks.getByName("copyLibFilesStandalone$t.capital").dependsOn(buildModuleWeb) webProject.tasks.getByName("copyLibFiles$t.capital").dependsOn(buildModuleWeb) - webProject.tasks.getByName("modularPublicationJar$t.capital").dependsOn(buildModuleWeb) def buildModuleSWT = task("buildModuleSWT$t.capital", type: Copy) { group = "Basic" @@ -6000,7 +5817,6 @@ compileTargets { t -> graphicsProject.tasks.getByName("copyNativeFilesStandalone$t.capital").dependsOn(buildModuleSWT) graphicsProject.tasks.getByName("copyLibFilesStandalone$t.capital").dependsOn(buildModuleSWT) graphicsProject.tasks.getByName("copyLibFiles$t.capital").dependsOn(buildModuleSWT) - graphicsProject.tasks.getByName("modularPublicationJar$t.capital").dependsOn(buildModuleSWT) dependsOn( buildModuleBaseTask, diff --git a/buildSrc/src/main/groovy/com/sun/javafx/gradle/CompileTarget.java b/buildSrc/src/main/groovy/com/sun/javafx/gradle/CompileTarget.java new file mode 100644 index 00000000000..ad1409aee70 --- /dev/null +++ b/buildSrc/src/main/groovy/com/sun/javafx/gradle/CompileTarget.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.sun.javafx.gradle; + +/** + * Struct used to contain some information passed to the closure + * passed to compileTargets. + */ +public class CompileTarget { + public String name; + public String upper; + public String capital; +} diff --git a/maven-publish.gradle b/maven-publish.gradle new file mode 100644 index 00000000000..2de38d2d583 --- /dev/null +++ b/maven-publish.gradle @@ -0,0 +1,213 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import com.sun.javafx.gradle.CompileTarget + +defineProperty("MAVEN_PUBLISH", "false") +ext.IS_MAVEN_PUBLISH = Boolean.parseBoolean(MAVEN_PUBLISH) +defineProperty("MAVEN_VERSION", IS_MAVEN_PUBLISH ? (ext.IS_MILESTONE_FCS ? project.ext.RELEASE_VERSION_SHORT : project.ext.RELEASE_VERSION_LONG) : "") +ext.MAVEN_GROUP_ID = "org.openjfx" + +logger.quiet("MAVEN_PUBLISH: $MAVEN_PUBLISH") +logger.quiet("MAVEN_VERSION: $MAVEN_VERSION") + +registerModules() + +void registerModules() { + if (!IS_MAVEN_PUBLISH) { + return + } + + Project base = project(":base") + Project graphics = project(":graphics") + Project controls = project(":controls") + Project fxml = project(":fxml") + Project media = project(":media") + + addMavenPublication(base, []) + addMavenPublication(graphics, [ base ]) + addMavenPublication(controls, [ graphics ]) + addMavenPublication(fxml, [ controls ]) + addMavenPublication(media, [ graphics ]) + + if (ext.COMPILE_SWING) { + addMavenPublication(project(":swing"), [ graphics ]) + } + + Project jsobject = project(":jsobject") + + addMavenPublication(jsobject, []) + addMavenPublication(project(":web"), [ controls, media, jsobject ]) + + // Incubator modules + Project incubatorInput = project(":incubator.input") + + addMavenPublication(incubatorInput, [ controls ]) + addMavenPublication(project(":incubator.richtext"), [ controls, incubatorInput ]) +} + +ext.configureMavenPublication = { List projects, CompileTarget t, Task previousTask -> + if (!IS_MAVEN_PUBLISH) { + return + } + + def targetProperties = project.ext[t.upper] + def platformPrefix = targetProperties.platformPrefix + + // Maven Publications + def publicationDirName = "${platformPrefix}publications" + def publicationDir = "${rootProject.layout.buildDirectory.get()}/${publicationDirName}" + + projects.each { Project project -> + def moduleName = project.ext.moduleName + def buildDir = project.layout.buildDirectory.get() + + def dstModularJarDir="${publicationDir}" + def srcClassesDir = "${buildDir}/${platformPrefix}module-classes" + def srcLibsDir = "${buildDir}/${platformPrefix}module-lib" + + def modularEmptyPublicationJarName = "${moduleName}.jar" + def modularEmptyPublicationJarTask = project.tasks.register("moduleEmptyPublicationJar${t.capital}", Jar) { + dependsOn previousTask + + destinationDirectory = file("${dstModularJarDir}") + archiveFileName = modularEmptyPublicationJarName + manifest { + attributes( + 'Automatic-Module-Name':"${moduleName}Empty" + ) + } + } + + def modularPublicationJarName = "${moduleName}-${t.name}.jar" + project.tasks.register("modularPublicationJar${t.capital}", Jar) { + dependsOn modularEmptyPublicationJarTask + + destinationDirectory = file("${dstModularJarDir}") + archiveFileName = modularPublicationJarName + from srcLibsDir + from srcClassesDir + } + } +} + +void addMavenPublication(Project project, List projectDependencies) { + if (!project.hasProperty("moduleName")) { + fail("Project ${project} has no module name") + } + projectDependencies.each { dep -> + if (!dep.hasProperty("moduleName")) { + fail("${project} dependency ${dep} has no module name") + } + } + + project.apply plugin: 'maven-publish' + + project.group = MAVEN_GROUP_ID + project.version = MAVEN_VERSION + + if (project.name == 'base') { + project.publishing { + publications { + javafx(MavenPublication) { + artifactId = 'javafx' + artifacts = [] + } + } + } + } + + gradle.taskGraph.whenReady { g -> + project.tasks.findAll { it.name == 'generatePomFileForJavafxPublication' }.each { it -> + it.doLast { + copy { + into project.file("${project.layout.buildDirectory.get()}/publications/javafx") + from file("${rootProject.projectDir}/javafx.pom") + rename "javafx.pom", "pom-default.xml" + filter { + line -> line.replaceAll("@VERSION@", MAVEN_VERSION) + } + } + } + } + } + + project.publishing { + repositories { + maven { + def repositoryUrl = project.hasProperty('repositoryUrl') ? project.getProperty('repositoryUrl') : "" + def repositoryUsername = project.hasProperty('repositoryUsername') ? project.getProperty('repositoryUsername') : "" + def repositoryPassword = project.hasProperty('repositoryPassword') ? project.getProperty('repositoryPassword') : "" + url repositoryUrl + credentials { + username repositoryUsername + password repositoryPassword + } + } + } + } + + compileTargets { CompileTarget t -> + project.publishing { + publications { + maven(MavenPublication) { + String artifactName = project.moduleName.replace('.', '-') + artifactId = artifactName + + afterEvaluate { + artifact project.tasks."moduleEmptyPublicationJar$t.capital" + artifact project.tasks."modularPublicationJar$t.capital" { + archiveClassifier.set("$t.name") + } + } + + pom.withXml { + Node parent = asNode().appendNode("parent") + parent.appendNode("groupId", MAVEN_GROUP_ID) + parent.appendNode("artifactId", "javafx") + parent.appendNode("version", MAVEN_VERSION) + + Node dependencies = asNode().appendNode("dependencies") + + Node projectDependencyPlatform = dependencies.appendNode("dependency") + projectDependencyPlatform.appendNode("groupId", MAVEN_GROUP_ID) + projectDependencyPlatform.appendNode("artifactId", artifactName) + projectDependencyPlatform.appendNode("version", MAVEN_VERSION) + projectDependencyPlatform.appendNode("classifier", "\${javafx.platform}") + + if (!projectDependencies.empty) { + projectDependencies.each { dep -> + String depName = dep.moduleName.replace('.', '-') + Node projectDependency = dependencies.appendNode("dependency") + projectDependency.appendNode("groupId", MAVEN_GROUP_ID) + projectDependency.appendNode("artifactId", depName) + projectDependency.appendNode("version", MAVEN_VERSION) + } + } + } + } + } + } + } +}