From 661648b3aa7e9fb5ffbe60fc77d8c7135668c66f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 24 Aug 2017 22:46:30 -0700 Subject: [PATCH] Build: Allow build to configure which license/notice to embed in jars (#26373) We currently add the apache license/notice for elasticsearch to any plugin that uses our ES plugin gradle plugin. However, each plugin should be able to use their own license. This commit adds a licenseFile and noticeFile property to the root of project's using BuildPlugin, which is added to jar files for that project. --- build.gradle | 13 +++++-------- .../org/elasticsearch/gradle/BuildPlugin.groovy | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 7af6ff736ce..583204196be 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.lib.RepositoryBuilder import org.gradle.plugins.ide.eclipse.model.SourceFolder import org.apache.tools.ant.taskdefs.condition.Os +import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.VersionProperties import org.elasticsearch.gradle.Version @@ -60,6 +61,10 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) { } } } + plugins.withType(BuildPlugin).whenPluginAdded { + project.licenseFile = project.rootProject.file('LICENSE.txt') + project.noticeFile = project.rootProject.file('NOTICE.txt') + } } /* Introspect all versions of ES that may be tested agains for backwards @@ -189,14 +194,6 @@ task branchConsistency { subprojects { project.afterEvaluate { - // include license and notice in jars - tasks.withType(Jar) { - into('META-INF') { - from project.rootProject.rootDir - include 'LICENSE.txt' - include 'NOTICE.txt' - } - } // ignore missing javadocs tasks.withType(Javadoc) { Javadoc javadoc -> // the -quiet here is because of a bug in gradle, in that adding a string option diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 62b2f4007a8..ee349345a21 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -36,6 +36,7 @@ import org.gradle.api.artifacts.ModuleVersionIdentifier import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.artifacts.dsl.RepositoryHandler +import org.gradle.api.file.CopySpec import org.gradle.api.plugins.JavaPlugin import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.plugins.MavenPublishPlugin @@ -502,6 +503,8 @@ class BuildPlugin implements Plugin { /** Adds additional manifest info to jars */ static void configureJars(Project project) { + project.ext.licenseFile = null + project.ext.noticeFile = null project.tasks.withType(Jar) { Jar jarTask -> // we put all our distributable files under distributions jarTask.destinationDir = new File(project.buildDir, 'distributions') @@ -525,6 +528,20 @@ class BuildPlugin implements Plugin { jarTask.manifest.attributes('Change': 'Unknown') } } + // add license/notice files + project.afterEvaluate { + if (project.licenseFile == null || project.noticeFile == null) { + throw new GradleException("Must specify license and notice file for project ${project.path}") + } + jarTask.into('META-INF') { + from(project.licenseFile.parent) { + include project.licenseFile.name + } + from(project.noticeFile.parent) { + include project.noticeFile.name + } + } + } } }