Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 66 additions & 39 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ void addJSL(Project project, String name, String pkg, List<String> addExports, C

}

void addMavenPublication(Project project, List<String> projectDependencies) {
void addMavenPublication(Project project) {
if (!IS_MAVEN_PUBLISH) {
return
}
Expand All @@ -1682,6 +1682,8 @@ void addMavenPublication(Project project, List<String> projectDependencies) {
project.version = MAVEN_VERSION

if (project.name == 'base') {
// The 'Parent POM' publication required only for Maven profiles.
// This is ignored by Gradle consumers as they use the Gradle metadata (.module) files.
project.publishing {
publications {
javafx(MavenPublication) {
Expand Down Expand Up @@ -1723,40 +1725,71 @@ void addMavenPublication(Project project, List<String> projectDependencies) {
}

compileTargets { t ->
def os = t.name
def arch, classifierSuffix
if (ARCH_NAME == 'x64') {
arch = MachineArchitecture.X86_64
classifierSuffix = ''
} else if (ARCH_NAME == 'aarch64') {
arch = MachineArchitecture.ARM64
classifierSuffix = '-aarch64'
} else {
fail("Publishing only configured for 'x64' and 'aarch64' architectures")
}
[project.configurations.apiElements, project.configurations.runtimeElements].each { conf ->
conf.outgoing {
variants.create(t.name) {
if (project.hasProperty('buildModule')) {
afterEvaluate {
artifact project.tasks."modularPublicationJar$t.capital" {
archiveClassifier = "$t.name$classifierSuffix"
}
}
}
attributes {
attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, os))
attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, arch))
}
}
}
project.components.java.withVariantsFromConfiguration(conf) {
// Skip the empty "main" variant for Gradle Metadata
if (!configurationVariant.attributes.contains(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE)) {
skip()
}
}
}

project.publishing {
publications {
maven(MavenPublication) {
from project.components.java

artifactId = "javafx-${project.name}"

afterEvaluate {
// add empty Jar as it will be expected by Maven consumers
artifact project.tasks."moduleEmptyPublicationJar$t.capital"
artifact project.tasks."modularPublicationJar$t.capital" {
classifier "$t.name"
}
}

pom.withXml {
Node parent = asNode().appendNode("parent")
Node parent = new Node(null, "parent")
parent.appendNode("groupId", MAVEN_GROUP_ID)
parent.appendNode("artifactId", "javafx")
parent.appendNode("version", MAVEN_VERSION)
asNode().children().add(4, parent)

Node dependencies = asNode().appendNode("dependencies")
Node dependencies = asNode().getByName("dependencies")[0]
if (!dependencies) {
dependencies = asNode().appendNode("dependencies")
}

Node projectDependencyPlatform = dependencies.appendNode("dependency")
Node projectDependencyPlatform = new Node(null, "dependency")
projectDependencyPlatform.appendNode("groupId", MAVEN_GROUP_ID)
projectDependencyPlatform.appendNode("artifactId", "javafx-${project.name}")
projectDependencyPlatform.appendNode("version", MAVEN_VERSION)
projectDependencyPlatform.appendNode("classifier", "\${javafx.platform}")

if (!projectDependencies.empty) {
projectDependencies.each { dep ->
Node projectDependency = dependencies.appendNode("dependency")
projectDependency.appendNode("groupId", MAVEN_GROUP_ID)
projectDependency.appendNode("artifactId", "javafx-$dep")
projectDependency.appendNode("version", MAVEN_VERSION)
}
}
dependencies.children().add(0, projectDependencyPlatform)
}
}
}
Expand Down Expand Up @@ -2061,7 +2094,7 @@ allprojects {

// All of our projects are java projects

apply plugin: "java"
apply plugin: 'java-library'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this change? This affects more than just the maven publishing, so I would like to make sure there are no implications to the rest of our build.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I explained in #1232 (comment) this changes the setup so that Gradle automatically generates the metadata (pom and module files) based on the "Model of the Software". Before the change, the metadata was completely constructed manually.

This change is needed in this PR to then extend the Model with the "Platform Variants" so that these are then also added to the metadata. (But it is in general a good improvement to let Gradle generate the metadata instead of to maintaining custom code for that).

In short you can say, all these changes pull things up one abstraction level. Instead of directly creating all metadata in the publications {} block, we give the information to Gradle in the "right place" so that it then has a complete and correct model of the JavaFX libraries and there relationships. From which it then creates the metadata when publishing.

This particular change here is needed, because since Gradle 4+, "java-library" is used to represent Java libraries. Which all of the JavaFX components are in Gradle terminology. This make the "api" scope for dependencies available we need further down.


// Set sourceCompatibility to the target release of Java. Most modules
// set compiler.options.release (to the same target version), which will
Expand Down Expand Up @@ -2212,7 +2245,7 @@ project(":base") {
sourceSets.main.java.srcDirs += "$buildDir/gensrc/java"

compileJava.dependsOn processVersionInfo
addMavenPublication(project, [])
addMavenPublication(project)

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -2252,7 +2285,7 @@ project(":graphics") {
dependencies {
antlr group: "org.antlr", name: "antlr4", version: "4.7.2", classifier: "complete"
testImplementation project(":base").sourceSets.test.output
implementation project(':base')
api project(':base')
Comment on lines 2287 to +2288
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here. This seems unrelated to the changes you are trying to make.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correcting the dependency scopes to be like they are in the pom after publishing. Because the information is correct here now, we no longer need the lists of dependency modules in these calls: addMavenPublication(project, [ 'base' ]) (in this example, the [base] is removed here).

}

project.ext.moduleSourcePath = defaultModuleSourcePath_GraphicsOne
Expand Down Expand Up @@ -2670,7 +2703,7 @@ project(":graphics") {
}
}

addMavenPublication(project, [ 'base' ])
addMavenPublication(project)

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -2705,8 +2738,7 @@ project(":controls") {
dependencies {
testImplementation project(":graphics").sourceSets.test.output
testImplementation project(":base").sourceSets.test.output
implementation project(':base')
implementation project(':graphics')
api project(':graphics')
}

test {
Expand Down Expand Up @@ -2747,7 +2779,7 @@ project(":controls") {
}
processShimsResources.dependsOn(copyShimBssTask)

addMavenPublication(project, [ 'graphics' ])
addMavenPublication(project)

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -2791,16 +2823,15 @@ project(":swing") {
commonModuleSetup(project, [ 'base', 'graphics', 'swing' ])

dependencies {
implementation project(":base")
implementation project(":graphics")
api project(":graphics")
}

test {
enabled = IS_FULL_TEST && IS_AWT_TEST
}

if (COMPILE_SWING) {
addMavenPublication(project, [ 'graphics' ])
addMavenPublication(project)
}

addValidateSourceSets(project, sourceSets)
Expand Down Expand Up @@ -2898,8 +2929,7 @@ project(":fxml") {
dependencies {
testImplementation project(":graphics").sourceSets.test.output
testImplementation project(":base").sourceSets.test.output
implementation project(":base")
implementation project(":graphics")
api project(":controls")
}

test {
Expand All @@ -2911,7 +2941,7 @@ project(":fxml") {
classpath += files("$JDK_HOME/jre/lib/ext/nashorn.jar")
}

addMavenPublication(project, [ 'controls' ])
addMavenPublication(project)

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -2950,8 +2980,7 @@ project(":media") {
media name: "ffmpeg-5.1.2", ext: "tar.gz"
media name: "ffmpeg-6.0", ext: "tar.gz"
}
implementation project(":base")
implementation project(":graphics")
api project(":graphics")
}

compileJava.dependsOn updateCacheIfNeeded
Expand Down Expand Up @@ -3518,7 +3547,7 @@ project(":media") {
}
}

addMavenPublication(project, [ 'graphics' ])
addMavenPublication(project)

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -3560,10 +3589,8 @@ project(":web") {
def icuFileVersion = icuVersion.replaceAll('\\.', '_')
icu name: "icu4c-${icuFileVersion}-data-bin-l", ext: "zip"
}
implementation project(":base")
implementation project(":graphics")
implementation project(":controls")
implementation project(":media")
api project(":controls")
api project(":media")
testImplementation project(":base").sourceSets.test.output
}

Expand Down Expand Up @@ -3801,7 +3828,7 @@ project(":web") {
assemble.dependsOn compileJavaDOMBinding, drtJar
}

addMavenPublication(project, [ 'controls', 'media' ])
addMavenPublication(project)

addValidateSourceSets(project, sourceSets)
}
Expand Down Expand Up @@ -5013,10 +5040,10 @@ compileTargets { t ->
}
}

def modularPublicationJarName = "${moduleName}-${t.name}.jar"
def modularPublicationJarTask = project.task("modularPublicationJar${t.capital}", type: Jar, dependsOn: modularEmptyPublicationJarTask) {
destinationDirectory = file("${dstModularJarDir}")
archiveFileName = modularPublicationJarName
archiveBaseName = moduleName
archiveClassifier = t.name
Comment on lines +5045 to +5046
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

Copy link
Author

@jjohannes jjohannes Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulling this up from the publications {} block (where this information is removed) into the "Model of the Software".

See also the ! part of the documentation here: https://docs.gradle.org/current/userguide/publishing_customization.html#sec:publishing_custom_artifacts_to_maven

from srcLibsDir
from srcClassesDir
}
Expand Down