Skip to content

Commit

Permalink
GEODE-8067: Improve manifest module resolution (apache#5660)
Browse files Browse the repository at this point in the history
* Improve project resolution of our nested subprojects for jar manifests
* Remove bom from modules list
* Move manifest module attributes to java config, not publish
  • Loading branch information
robbadler authored Oct 23, 2020
1 parent 872718e commit 0fdfc1a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 56 deletions.
2 changes: 1 addition & 1 deletion geode-cq/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply from: "${project.projectDir}/../gradle/publish-java.gradle"


dependencies {
compile(platform(project(':boms:geode-all-bom')))
implementation(platform(project(':boms:geode-all-bom')))
implementation(project(':geode-core'))
implementation(project(':geode-logging'))
implementation(project(':geode-membership'))
Expand Down
2 changes: 1 addition & 1 deletion geode-lucene/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ apply from: "${project.projectDir}/../gradle/publish-java.gradle"


dependencies {
compile(platform(project(':boms:geode-all-bom')))
api(platform(project(':boms:geode-all-bom')))

api(project(':geode-core'))
api('org.apache.lucene:lucene-core')
Expand Down
57 changes: 50 additions & 7 deletions gradle/java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,58 @@ gradle.taskGraph.whenReady({ graph ->
// apply default manifest
gradle.taskGraph.whenReady({ graph ->
tasks.withType(Jar).each { jar ->
jar.doFirst {
manifest {
attributes.put("Manifest-Version", "1.0")
attributes.put("Created-By", System.getProperty("user.name"))
attributes.put("Title", rootProject.name)
attributes.put("Version", version)
attributes.put("Organization", productOrg)

def projectDependencies = []
def runtimeList = []
def allProjectDeps = []

def confList = ['api', 'implementation', 'runtimeOnly']
confList.each { conf ->
allProjectDeps.addAll(project.configurations.getByName(conf).getDependencies())
}

// Iterate over runtime classpath dependencies and separate project dependencies from library
// dependencies.
allProjectDeps.each { dependency ->
if ( dependency instanceof ProjectDependency ) {
def platformAttribute = Attribute.of("org.gradle.category", org.gradle.api.attributes.Category.class)
def foundAttribute = dependency.attributes.getAttribute(platformAttribute)
if ( foundAttribute == null) {
projectDependencies.add(dependency)
} else if ('platform'.equals(foundAttribute)) {
projectDependencies.add(dependency)
}
} else {
project.configurations.runtimeClasspath.files(dependency).each { depJar ->
runtimeList.add(depJar.name)
}
}
}

// Iterate over project (parent) dependencies and remove its runtime library dependencies from
// the current project's runtime library dependencies.
// Also removes all parent project's runtime project dependencies from the current project.
// This returns a unique set of parent project and library dependencies that are not found
// within it's parent's project dependencies.
projectDependencies.clone().each { ProjectDependency projectDependency ->
Project geodeProject = projectDependency.getDependencyProject()
def collect = geodeProject.configurations.runtimeClasspath.collect { it.name }
runtimeList.removeAll(collect)
// projectDependencies.removeAll(collect.collect {it-".jar"})
}

jar.doFirst {
manifest {
attributes.put("Manifest-Version", "1.0")
attributes.put("Created-By", System.getProperty("user.name"))
attributes.put("Title", rootProject.name)
attributes.put("Version", version)
attributes.put("Organization", productOrg)
attributes.put("Class-Path", runtimeList.join(' '))
attributes.put("Dependent-Modules", projectDependencies.collect({ "${it.name}-${it.version}" }).join(' '))
attributes.put("Module-Name", project.name)
}
}
jar.metaInf {
from("$rootDir/geode-assembly/src/main/dist/LICENSE")
if (jar.source.filter({ it.name.contains('NOTICE') }).empty) {
Expand Down
47 changes: 0 additions & 47 deletions gradle/publish-java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,3 @@ publishing {
}
}
}

gradle.taskGraph.whenReady({ graph ->
tasks.withType(Jar).each { jar ->
jar.doFirst {
def projectDependencies = []
def runtimeList = []

// Iterate over runtime classpath dependencies and separate project dependencies from library
// dependencies.
configurations.runtimeClasspath
.collect { it.name - ".jar" }
.each { dependency ->
if (dependency.startsWith("geode-")) {
projectDependencies.add(dependency)
} else {
runtimeList.add(dependency+".jar")
}
}

// Iterate over project (parent) dependencies and remove its runtime library dependencies from
// the current project's runtime library dependencies.
// Also removes all parent project's runtime project dependencies from the current project.
// This returns a unique set of parent project and library dependencies that are not found
// within it's parent's project dependencies.
projectDependencies.clone().each { projectDependency ->
def geodeProject = projectDependency - "-${version}.jar"
if (projectDependencies.contains(geodeProject)) {
try {
def parentProject = project(":$geodeProject" - "-$version")
def collect = parentProject.configurations.runtimeClasspath.collect { it.name }
runtimeList.removeAll(collect)
projectDependencies.removeAll(collect.collect {it-".jar"})
} catch (UnknownProjectException ignore) {
}
}
}

manifest {
attributes.put("Class-Path", runtimeList.join(' '))
attributes.put("Dependent-Modules", projectDependencies.join(' '))
attributes.put("Module-Name", project.name)
}
}
}
})


0 comments on commit 0fdfc1a

Please sign in to comment.