Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjincheng121 committed Jan 8, 2020
1 parent 282bd36 commit 328c202
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Expand Up @@ -318,7 +318,14 @@ if (project.hasProperty('javaLinkageArtifactIds')) {
dependsOn project.getTasksByName('publishMavenJavaPublicationToMavenLocal', true /* recursively */)
classpath = project.configurations.linkageCheckerJava
main = 'com.google.cloud.tools.opensource.classpath.LinkageCheckerMain'
args '-a', project.javaLinkageArtifactIds.split(',').collect({"${project.ext.mavenGroupId}:${it}:0.1"}).join(',')
args '-a', project.javaLinkageArtifactIds.split(',').collect({
if (it.contains(':')) {
"${project.ext.mavenGroupId}:${it}"
} else {
// specify the version if not provided
"${project.ext.mavenGroupId}:${it}:${project.version}"
}
}).join(',')
doLast {
println "NOTE: This task published artifacts into your local Maven repository. You may want to remove them manually."
}
Expand Down
Expand Up @@ -21,9 +21,7 @@ package org.apache.beam.gradle
import org.gradle.api.Project

/**
* Utilities for working with our vendored version of gRPC. The test dependency junit and the runtime dependencies
* slf4j, commons-logging and log4j are not included in the vendored jar. The linkage checker complains about
* these dependencies could be ignored.
* Utilities for working with our vendored version of gRPC.
*/
class GrpcVendoring_1_26_0 {
/** Returns the list of compile time dependencies. */
Expand Down
Expand Up @@ -21,6 +21,7 @@ package org.apache.beam.gradle
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.file.FileTree
import org.gradle.api.publish.maven.MavenPublication

Expand Down Expand Up @@ -97,8 +98,8 @@ class VendorJavaPlugin implements Plugin<Project> {

project.dependencies {
config.dependencies.each { compile it }
config.runtimeDependencies.each { runtime it }
config.testDependencies.each { testImplementation it}
config.runtimeDependencies.each { runtimeOnly it }
config.testDependencies.each { compileOnly it}
}

// Create a task which emulates the maven-archiver plugin in generating a
Expand Down Expand Up @@ -283,6 +284,55 @@ artifactId=${project.name}
}

pom.withXml {
def root = asNode()
def dependenciesNode = root.appendNode('dependencies')
def generateDependenciesFromConfiguration = { param ->
project.configurations."${param.configuration}".allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
def appendClassifier = { dep ->
dep.artifacts.each { art ->
if (art.hasProperty('classifier')) {
dependencyNode.appendNode('classifier', art.classifier)
}
}
}

if (it instanceof ProjectDependency) {
dependencyNode.appendNode('groupId', it.getDependencyProject().mavenGroupId)
dependencyNode.appendNode('artifactId', it.getDependencyProject().archivesBaseName)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', param.scope)
appendClassifier(it)
} else {
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', param.scope)
appendClassifier(it)
}

// Start with any exclusions that were added via configuration exclude rules.
// Then add all the exclusions that are specific to the dependency (if any
// were declared). Finally build the node that represents all exclusions.
def exclusions = []
exclusions += project.configurations."${param.configuration}".excludeRules
if (it.hasProperty('excludeRules')) {
exclusions += it.excludeRules
}
if (!exclusions.empty) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
exclusions.each { exclude ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', exclude.group)
exclusionNode.appendNode('artifactId', exclude.module)
}
}
}
}

generateDependenciesFromConfiguration(configuration: 'runtimeOnly', scope: 'runtime')
generateDependenciesFromConfiguration(configuration: 'compileOnly', scope: 'provided')

// NB: This must come after asNode() logic, as it seems asNode()
// removes XML comments.
// TODO: Load this from file?
Expand Down
5 changes: 3 additions & 2 deletions vendor/README.md
Expand Up @@ -31,7 +31,8 @@ The upgrading of the vendored dependencies should be performed in two steps:
The [linkage tool](https://lists.apache.org/thread.html/eb5d95b9a33d7e32dc9bcd0f7d48ba8711d42bd7ed03b9cf0f1103f1%40%3Cdev.beam.apache.org%3E)
is useful for the vendored dependency upgrades. It reports the linkage errors across multiple Apache Beam artifact ids.

For example, when we upgrade the vendored gRPC to 1.26.0, we could run the linkage tool as following:
For example, when we upgrade the version of gRPC to 1.26.0 and the version of the vendored gRPC is 0.1-SNAPSHOT,
we could run the linkage tool as following:
```
./gradlew -Ppublishing -PjavaLinkageArtifactIds=beam-vendor-grpc-1_26_0 :checkJavaLinkage
./gradlew -PvendoredDependenciesOnly -Ppublishing -PjavaLinkageArtifactIds=beam-vendor-grpc-1_26_0:0.1-SNAPSHOT :checkJavaLinkage
```

0 comments on commit 328c202

Please sign in to comment.