-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further simplification of the ZIP publication implementation
This is WIP, and I am kindly asking for a feedback. This is a follow-up to PR #4156 and brings in a further simplification of the ZIP publication implementation and a new gradle test. In the mentioned PR we specifically implemented the functionality to use `project.group` value for the `artifactId` and if there was an override provided by user (ie the `groupId` value was explicitly specified in POM configuration) then it was used instead. Further, we were explicitly setting the artifactId and version as well. But in fact all this has been already happening under the hood (by the libraries that do the heavy lifting of publication tasks processing). There is really no need to (re-)implement it again. As we can see from the modified code and tests that we can perfectly remove almost all the ZIP publication initialization code and all the things still work as expected. And I think it is because this is how the Project Object Model (POM) was designed to work. Because of that the condition to test the groupId presence: `if groupId == null` was useless. It was never `true`. If the `project.group` is not defined the publication task fails with an exception (we test it), if there is a custom `groupId` value setup in publication config then it overrides the `project.group` as well. Again, we test it. :-) On top of that I am not really sure if we needed the condition to test: `if (mavenZip == null)` and create a new instance of MavenPublication if it is null. Hence, I removed it and all the tests are still fine. Actually, I can not think of a case where the condition would be met (please prove me wrong). I added a new test to verify we can run "publishToMavenLocal" and get expected results. The inspiration for this comes from opensearch-project/opensearch-plugin-template-java#35 Signed-off-by: Lukáš Vlček <lukas.vlcek@aiven.io>
- Loading branch information
1 parent
54364a5
commit 91a3fac
Showing
5 changed files
with
182 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
buildSrc/src/test/resources/pluginzip/publishToMavenLocal.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
plugins { | ||
// The java-gradle-plugin adds a new publication called 'pluginMaven' that causes some warnings because it | ||
// clashes a bit with other publications defined in this file. If you are running at the --info level then you can | ||
// expect some warning like the following: | ||
// "Multiple publications with coordinates 'org.custom.group:sample-plugin:2.0.0.0' are published to repository 'mavenLocal'." | ||
id 'java-gradle-plugin' | ||
|
||
// https://github.com/nebula-plugins/nebula-publishing-plugin#nebulamaven-base-publish | ||
// id 'nebula.maven-base-publish' | ||
|
||
id 'maven-publish' | ||
id 'opensearch.pluginzip' | ||
} | ||
|
||
group="org.custom.group" | ||
version='2.0.0.0' | ||
|
||
// A bundlePlugin task mockup | ||
tasks.register('bundlePlugin', Zip.class) { | ||
archiveFileName = "sample-plugin-${version}.zip" | ||
destinationDirectory = layout.buildDirectory.dir('distributions') | ||
from layout.projectDirectory.file('sample-plugin-source.txt') | ||
} | ||
|
||
// A task to prepare directory for a temporary maven local repository | ||
tasks.register('prepareLocalMVNRepo') { | ||
dependsOn ':bundlePlugin' | ||
doFirst { | ||
File localMVNRepo = new File (layout.buildDirectory.get().getAsFile().getPath(), 'local-staging-repo') | ||
System.out.println('Creating temporary folder for mavenLocal repo: '+ localMVNRepo.toString()) | ||
System.out.println("Success: " + localMVNRepo.mkdir()) | ||
} | ||
} | ||
|
||
publishing { | ||
publications { | ||
// Plugin zip publication | ||
pluginZip(MavenPublication) { | ||
pom { | ||
url = 'http://www.example.com/library' | ||
description = 'pluginZip publication' | ||
} | ||
} | ||
// Standard maven publication | ||
mavenJava(MavenPublication) { | ||
pom { | ||
url = 'http://www.example.com/library' | ||
description = 'mavenJava publication' | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters