You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.5 KiB
65 lines
2.5 KiB
12 years ago
|
/**
|
||
12 years ago
|
* Will merge the artifacts of the current project into mergeIntoProject. For example, to
|
||
|
* bundle spring-test-mvc in spring-test's jars. This script will perform the following
|
||
|
* steps:
|
||
|
*
|
||
|
* - Ensure that jar tasks of the project being merged from will execute the tasks of the
|
||
|
* project being merged into
|
||
|
*
|
||
|
* - Add the project being merged into to the classpath of the project being merged from
|
||
|
*
|
||
|
* - Update the pom.xml of the project being merged into to contain the entries from the
|
||
|
* project being merged from
|
||
12 years ago
|
*
|
||
|
* Example Usage:
|
||
|
*
|
||
12 years ago
|
* ext.mergeIntoProject = project(':spring-test')
|
||
|
* apply from: "${rootProject.projectDir}/gradle/merge-artifacts.gradle"
|
||
12 years ago
|
*/
|
||
|
|
||
|
def mergeFromProject = project
|
||
|
|
||
|
// invoking a task on mergeFromProject will invoke the task with the same name on mergeIntoProject
|
||
12 years ago
|
def taskNamesToMerge = ['sourcesJar','jar','javadocJar','javadoc','install','artifactoryPublish']
|
||
12 years ago
|
taskNamesToMerge.each { taskName ->
|
||
12 years ago
|
def taskToRemove = mergeFromProject.tasks.findByPath(taskName)
|
||
|
if(taskToRemove) {
|
||
|
taskToRemove.enabled = false
|
||
|
taskToRemove.dependsOn mergeIntoProject."$taskName"
|
||
|
}
|
||
12 years ago
|
}
|
||
|
|
||
|
// update mergeIntoProject artifacts to contain the mergeFromProject artifact contents
|
||
|
mergeIntoProject."sourcesJar" {
|
||
|
from mergeFromProject.sourcesJar.source
|
||
|
}
|
||
|
mergeIntoProject."jar" {
|
||
|
from mergeFromProject.jar.source
|
||
|
}
|
||
|
mergeIntoProject."javadoc" {
|
||
|
source += mergeFromProject.javadoc.source
|
||
|
classpath += mergeFromProject.javadoc.classpath
|
||
|
}
|
||
|
|
||
|
// Update mergeIntoProject to contain additional configurations that contains all the dependencies from mergeFromProject
|
||
|
// so that Maven pom generation works
|
||
|
gradle.taskGraph.whenReady {
|
||
|
mergeFromProject.configurations.archives.artifacts.clear()
|
||
|
|
||
|
mergeFromProject.configurations.each { config->
|
||
|
def mapping = mergeFromProject.conf2ScopeMappings.getMapping([config])
|
||
|
if(mapping.scope) {
|
||
|
def newConfigName = mergeFromProject.name + "-"+ config.name
|
||
|
mergeIntoProject.configurations.add(newConfigName)
|
||
|
config.dependencies.each { dependency ->
|
||
|
mergeIntoProject.dependencies.add(newConfigName, dependency)
|
||
|
}
|
||
|
configure(mergeIntoProject.install.repositories.mavenInstaller.pom.scopeMappings) {
|
||
|
addMapping(mapping.priority + 100, mergeIntoProject.configurations."$newConfigName", mapping.scope)
|
||
|
}
|
||
|
mergeIntoProject.optionalDeps += mergeFromProject.optionalDeps
|
||
|
mergeIntoProject.providedDeps += mergeFromProject.providedDeps
|
||
|
}
|
||
|
}
|
||
|
}
|