-
Notifications
You must be signed in to change notification settings - Fork 545
Publish Gradle Metadata with variants and attributes #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| } | ||
|
|
@@ -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) { | ||
|
|
@@ -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) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -2061,7 +2094,7 @@ allprojects { | |
|
|
||
| // All of our projects are java projects | ||
|
|
||
| apply plugin: "java" | ||
| apply plugin: 'java-library' | ||
|
|
||
| // Set sourceCompatibility to the target release of Java. Most modules | ||
| // set compiler.options.release (to the same target version), which will | ||
|
|
@@ -2212,7 +2245,7 @@ project(":base") { | |
| sourceSets.main.java.srcDirs += "$buildDir/gensrc/java" | ||
|
|
||
| compileJava.dependsOn processVersionInfo | ||
| addMavenPublication(project, []) | ||
| addMavenPublication(project) | ||
|
|
||
| addValidateSourceSets(project, sourceSets) | ||
| } | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
|
||
| project.ext.moduleSourcePath = defaultModuleSourcePath_GraphicsOne | ||
|
|
@@ -2670,7 +2703,7 @@ project(":graphics") { | |
| } | ||
| } | ||
|
|
||
| addMavenPublication(project, [ 'base' ]) | ||
| addMavenPublication(project) | ||
|
|
||
| addValidateSourceSets(project, sourceSets) | ||
| } | ||
|
|
@@ -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 { | ||
|
|
@@ -2747,7 +2779,7 @@ project(":controls") { | |
| } | ||
| processShimsResources.dependsOn(copyShimBssTask) | ||
|
|
||
| addMavenPublication(project, [ 'graphics' ]) | ||
| addMavenPublication(project) | ||
|
|
||
| addValidateSourceSets(project, sourceSets) | ||
| } | ||
|
|
@@ -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) | ||
|
|
@@ -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 { | ||
|
|
@@ -2911,7 +2941,7 @@ project(":fxml") { | |
| classpath += files("$JDK_HOME/jre/lib/ext/nashorn.jar") | ||
| } | ||
|
|
||
| addMavenPublication(project, [ 'controls' ]) | ||
| addMavenPublication(project) | ||
|
|
||
| addValidateSourceSets(project, sourceSets) | ||
| } | ||
|
|
@@ -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 | ||
|
|
@@ -3518,7 +3547,7 @@ project(":media") { | |
| } | ||
| } | ||
|
|
||
| addMavenPublication(project, [ 'graphics' ]) | ||
| addMavenPublication(project) | ||
|
|
||
| addValidateSourceSets(project, sourceSets) | ||
| } | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
|
|
@@ -3801,7 +3828,7 @@ project(":web") { | |
| assemble.dependsOn compileJavaDOMBinding, drtJar | ||
| } | ||
|
|
||
| addMavenPublication(project, [ 'controls', 'media' ]) | ||
| addMavenPublication(project) | ||
|
|
||
| addValidateSourceSets(project, sourceSets) | ||
| } | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pulling this up from the 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 | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 (
pomandmodulefiles) 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.