@@ -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) }
0 commit comments