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.
This commit is contained in:
parent
0390c76f0a
commit
661648b3aa
13
build.gradle
13
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
|
||||
|
|
|
@ -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<Project> {
|
|||
|
||||
/** 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<Project> {
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue