Skip to content

Commit c0ee68b

Browse files
authored
Move publishing configuration to a separate plugin (#56727)
This is another part of the breakup of the massive BuildPlugin. This PR moves the code for configuring publications to a separate plugin. Most of the time these publications are jar files, but this also supports the zip publication we have for integ tests.
1 parent cad030d commit c0ee68b

File tree

29 files changed

+350
-277
lines changed

29 files changed

+350
-277
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if (project == rootProject) {
159159
// to enforce precommit checks like forbidden apis, as well as setup publishing
160160
if (project != rootProject) {
161161
apply plugin: 'elasticsearch.build'
162-
apply plugin: 'nebula.maven-base-publish'
162+
apply plugin: 'elasticsearch.publish'
163163

164164
// groovydoc succeeds, but has some weird internal exception...
165165
groovydoc.enabled = false

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 1 addition & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ class BuildPlugin implements Plugin<Project> {
110110
)
111111
}
112112
project.pluginManager.apply('elasticsearch.java')
113-
configureJars(project)
114-
configureJarManifest(project)
113+
project.pluginManager.apply('elasticsearch.publish')
115114

116115
// apply global test task failure listener
117116
project.rootProject.pluginManager.apply(TestFailureReportingPlugin)
@@ -120,9 +119,6 @@ class BuildPlugin implements Plugin<Project> {
120119

121120
configureRepositories(project)
122121
project.extensions.getByType(ExtraPropertiesExtension).set('versions', VersionProperties.versions)
123-
configureJavadoc(project)
124-
configureSourcesJar(project)
125-
configurePomGeneration(project)
126122
configurePrecommit(project)
127123
configureDependenciesInfo(project)
128124
configureFips140(project)
@@ -288,206 +284,6 @@ class BuildPlugin implements Plugin<Project> {
288284
}
289285
}
290286

291-
/**Configuration generation of maven poms. */
292-
static void configurePomGeneration(Project project) {
293-
project.plugins.withType(MavenPublishPlugin).whenPluginAdded {
294-
TaskProvider generatePomTask = project.tasks.register("generatePom") { Task task ->
295-
task.dependsOn 'generatePomFileForNebulaPublication'
296-
}
297-
298-
maybeConfigure(project.tasks, LifecycleBasePlugin.ASSEMBLE_TASK_NAME) { assemble ->
299-
assemble.dependsOn(generatePomTask)
300-
}
301-
302-
project.tasks.withType(GenerateMavenPom).configureEach({ GenerateMavenPom pomTask ->
303-
pomTask.destination = { "${project.buildDir}/distributions/${project.convention.getPlugin(BasePluginConvention).archivesBaseName}-${project.version}.pom" }
304-
} as Action<GenerateMavenPom>)
305-
306-
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
307-
308-
project.pluginManager.withPlugin('com.github.johnrengelman.shadow') {
309-
MavenPublication publication = publishing.publications.maybeCreate('shadow', MavenPublication)
310-
ShadowExtension shadow = project.extensions.getByType(ShadowExtension)
311-
shadow.component(publication)
312-
// Workaround for https://github.com/johnrengelman/shadow/issues/334
313-
// Here we manually add any project dependencies in the "shadow" configuration to our generated POM
314-
publication.pom.withXml(this.&addScmInfo)
315-
publication.pom.withXml { xml ->
316-
Node root = xml.asNode()
317-
root.appendNode('name', project.name)
318-
root.appendNode('description', project.description)
319-
Node dependenciesNode = (root.get('dependencies') as NodeList).get(0) as Node
320-
project.configurations.getByName(ShadowBasePlugin.CONFIGURATION_NAME).allDependencies.each { dependency ->
321-
if (dependency instanceof ProjectDependency) {
322-
def dependencyNode = dependenciesNode.appendNode('dependency')
323-
dependencyNode.appendNode('groupId', dependency.group)
324-
dependencyNode.appendNode('artifactId', dependency.getDependencyProject().convention.getPlugin(BasePluginConvention).archivesBaseName)
325-
dependencyNode.appendNode('version', dependency.version)
326-
dependencyNode.appendNode('scope', 'compile')
327-
}
328-
}
329-
}
330-
generatePomTask.configure({ Task t -> t.dependsOn = ['generatePomFileForShadowPublication'] } as Action<Task>)
331-
332-
// have to defer this until archivesBaseName is set
333-
project.afterEvaluate {
334-
publication.artifactId = project.convention.getPlugin(BasePluginConvention).archivesBaseName
335-
}
336-
}
337-
}
338-
339-
// Add git origin info to generated POM files
340-
project.pluginManager.withPlugin('nebula.maven-base-publish') {
341-
PublishingExtension publishing = project.extensions.getByType(PublishingExtension)
342-
MavenPublication nebulaPublication = (MavenPublication) publishing.publications.getByName('nebula')
343-
nebulaPublication.pom.withXml(this.&addScmInfo)
344-
345-
// have to defer this until archivesBaseName is set
346-
project.afterEvaluate {
347-
nebulaPublication.artifactId = project.convention.getPlugin(BasePluginConvention).archivesBaseName
348-
}
349-
}
350-
}
351-
352-
private static void addScmInfo(XmlProvider xml) {
353-
Node root = xml.asNode()
354-
root.appendNode('url', PluginBuildPlugin.urlFromOrigin(BuildParams.gitOrigin))
355-
Node scmNode = root.appendNode('scm')
356-
scmNode.appendNode('url', BuildParams.gitOrigin)
357-
}
358-
359-
static void configureJavadoc(Project project) {
360-
// remove compiled classes from the Javadoc classpath: http://mail.openjdk.java.net/pipermail/javadoc-dev/2018-January/000400.html
361-
final List<File> classes = new ArrayList<>()
362-
project.tasks.withType(JavaCompile).configureEach { JavaCompile javaCompile ->
363-
classes.add(javaCompile.destinationDir)
364-
}
365-
project.tasks.withType(Javadoc).configureEach { Javadoc javadoc ->
366-
// only explicitly set javadoc executable if compiler JDK is different from Gradle
367-
// this ensures better cacheability as setting ths input to an absolute path breaks portability
368-
if (Files.isSameFile(BuildParams.compilerJavaHome.toPath(), Jvm.current().getJavaHome().toPath()) == false) {
369-
javadoc.executable = new File(BuildParams.compilerJavaHome, 'bin/javadoc')
370-
}
371-
javadoc.classpath = javadoc.getClasspath().filter { f ->
372-
return classes.contains(f) == false
373-
}
374-
/*
375-
* Generate docs using html5 to suppress a warning from `javadoc`
376-
* that the default will change to html5 in the future.
377-
*/
378-
(javadoc.options as CoreJavadocOptions).addBooleanOption('html5', true)
379-
}
380-
// ensure javadoc task is run with 'check'
381-
project.pluginManager.withPlugin('lifecycle-base') {
382-
project.tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME).configure { it.dependsOn(project.tasks.withType(Javadoc)) }
383-
}
384-
configureJavadocJar(project)
385-
}
386-
387-
/** Adds a javadocJar task to generate a jar containing javadocs. */
388-
static void configureJavadocJar(Project project) {
389-
TaskProvider<Jar> javadocJarTask = project.tasks.register('javadocJar', Jar, { Jar jar ->
390-
jar.archiveClassifier.set('javadoc')
391-
jar.group = 'build'
392-
jar.description = 'Assembles a jar containing javadocs.'
393-
jar.from(project.tasks.named(JavaPlugin.JAVADOC_TASK_NAME))
394-
} as Action<Jar>)
395-
maybeConfigure(project.tasks, BasePlugin.ASSEMBLE_TASK_NAME) { Task t ->
396-
t.dependsOn(javadocJarTask)
397-
}
398-
}
399-
400-
static void configureSourcesJar(Project project) {
401-
TaskProvider<Jar> sourcesJarTask = project.tasks.register('sourcesJar', Jar, { Jar jar ->
402-
jar.archiveClassifier.set('sources')
403-
jar.group = 'build'
404-
jar.description = 'Assembles a jar containing source files.'
405-
jar.from(project.extensions.getByType(SourceSetContainer).getByName(SourceSet.MAIN_SOURCE_SET_NAME).allSource)
406-
} as Action<Jar>)
407-
maybeConfigure(project.tasks, BasePlugin.ASSEMBLE_TASK_NAME) { Task t ->
408-
t.dependsOn(sourcesJarTask)
409-
}
410-
}
411-
412-
/** Adds additional manifest info to jars */
413-
static void configureJars(Project project) {
414-
ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension)
415-
ext.set('licenseFile', null)
416-
ext.set('noticeFile', null)
417-
project.tasks.withType(Jar).configureEach { Jar jarTask ->
418-
// we put all our distributable files under distributions
419-
jarTask.destinationDirectory.set(new File(project.buildDir, 'distributions'))
420-
// fixup the jar manifest
421-
jarTask.doFirst {
422-
// this doFirst is added before the info plugin, therefore it will run
423-
// after the doFirst added by the info plugin, and we can override attributes
424-
JavaVersion compilerJavaVersion = BuildParams.compilerJavaVersion
425-
jarTask.manifest.attributes(
426-
'Build-Date': BuildParams.buildDate,
427-
'Build-Java-Version': BuildParams.compilerJavaVersion)
428-
}
429-
}
430-
// add license/notice files
431-
project.afterEvaluate {
432-
project.tasks.withType(Jar).configureEach { Jar jarTask ->
433-
if (ext.has('licenseFile') == false || ext.get('licenseFile') == null || ext.has('noticeFile') == false || ext.get('noticeFile') == null) {
434-
throw new GradleException("Must specify license and notice file for project ${project.path}")
435-
}
436-
437-
File licenseFile = ext.get('licenseFile') as File
438-
File noticeFile = ext.get('noticeFile') as File
439-
440-
jarTask.metaInf { CopySpec spec ->
441-
spec.from(licenseFile.parent) { CopySpec from ->
442-
from.include licenseFile.name
443-
from.rename { 'LICENSE.txt' }
444-
}
445-
spec.from(noticeFile.parent) { CopySpec from ->
446-
from.include noticeFile.name
447-
from.rename { 'NOTICE.txt' }
448-
}
449-
}
450-
}
451-
}
452-
project.pluginManager.withPlugin('com.github.johnrengelman.shadow') {
453-
project.tasks.getByName(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME).configure { ShadowJar shadowJar ->
454-
/*
455-
* Replace the default "-all" classifier with null
456-
* which will leave the classifier off of the file name.
457-
*/
458-
shadowJar.archiveClassifier.set((String) null)
459-
/*
460-
* Not all cases need service files merged but it is
461-
* better to be safe
462-
*/
463-
shadowJar.mergeServiceFiles()
464-
}
465-
// Add "original" classifier to the non-shadowed JAR to distinguish it from the shadow JAR
466-
project.tasks.getByName(JavaPlugin.JAR_TASK_NAME).configure { Jar jar ->
467-
jar.archiveClassifier.set('original')
468-
}
469-
// Make sure we assemble the shadow jar
470-
project.tasks.named(BasePlugin.ASSEMBLE_TASK_NAME).configure { Task task ->
471-
task.dependsOn 'shadowJar'
472-
}
473-
}
474-
}
475-
476-
static void configureJarManifest(Project project) {
477-
project.pluginManager.apply('nebula.info-broker')
478-
project.pluginManager.apply('nebula.info-basic')
479-
project.pluginManager.apply('nebula.info-java')
480-
project.pluginManager.apply('nebula.info-jar')
481-
482-
project.plugins.withId('nebula.info-broker') { InfoBrokerPlugin manifestPlugin ->
483-
manifestPlugin.add('Module-Origin') { BuildParams.gitOrigin }
484-
manifestPlugin.add('Change') { BuildParams.gitRevision }
485-
manifestPlugin.add('X-Compile-Elasticsearch-Version') { VersionProperties.elasticsearch }
486-
manifestPlugin.add('X-Compile-Lucene-Version') { VersionProperties.lucene }
487-
manifestPlugin.add('X-Compile-Elasticsearch-Snapshot') { VersionProperties.isElasticsearchSnapshot() }
488-
}
489-
}
490-
491287
private static configurePrecommit(Project project) {
492288
TaskProvider precommit = PrecommitTasks.create(project, true)
493289
project.tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME).configure { it.dependsOn(precommit) }

buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,6 @@ class PluginBuildPlugin implements Plugin<Project> {
226226
project.artifacts.add('zip', bundle)
227227
}
228228

229-
static final Pattern GIT_PATTERN = Pattern.compile(/git@([^:]+):([^\.]+)\.git/)
230-
231-
/** Find the reponame. */
232-
static String urlFromOrigin(String origin) {
233-
if (origin == null) {
234-
return null // best effort, the url doesnt really matter, it is just required by maven central
235-
}
236-
if (origin.startsWith('https')) {
237-
return origin
238-
}
239-
Matcher matcher = GIT_PATTERN.matcher(origin)
240-
if (matcher.matches()) {
241-
return "https://${matcher.group(1)}/${matcher.group(2)}"
242-
} else {
243-
return origin // best effort, the url doesnt really matter, it is just required by maven central
244-
}
245-
}
246-
247229
/** Configure the pom for the main jar of this plugin */
248230

249231
protected static void addNoticeGeneration(Project project, PluginPropertiesExtension extension) {

0 commit comments

Comments
 (0)