-
Notifications
You must be signed in to change notification settings - Fork 105
build: refactor Gradle build #1539
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,44 +13,42 @@ plugins { | |
// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync) | ||
project.version = "2.6.1-SNAPSHOT" // {x-version-update:gax:current} | ||
|
||
ext { | ||
// Project names not used for release | ||
nonReleaseProjects = ['benchmark'] | ||
// Project names not using the default publication configuration | ||
noDefaultPublications = ['benchmark', 'gax-bom'] | ||
libraryVendor = 'Google' | ||
// Project names not used for release | ||
def nonReleaseProjects = ['benchmark'] | ||
// Project names not using the default publication configuration | ||
def noDefaultPublications = ['benchmark', 'gax-bom'] | ||
def nonJavaProjects = ['gax-bom'] | ||
|
||
ext.libraryVendor = 'Google' | ||
|
||
allprojects { | ||
group = 'com.google.api' | ||
} | ||
|
||
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword') && | ||
!nonReleaseProjects.contains(project.name)) { | ||
nexusPublishing { | ||
packageGroup = 'com.google.api' | ||
repositories { | ||
sonatype { //or custom repository name | ||
nexusUrl.set(uri('https://google.oss.sonatype.org/service/local/')) | ||
snapshotRepositoryUrl.set(uri('https://google.oss.sonatype.org/content/repositories/snapshots/')) | ||
username = ossrhUsername | ||
password = ossrhPassword | ||
} | ||
nexusPublishing { | ||
packageGroup = 'com.google.api' | ||
repositories { | ||
sonatype { | ||
nexusUrl = uri('https://google.oss.sonatype.org/service/local/') | ||
snapshotRepositoryUrl = uri('https://google.oss.sonatype.org/content/repositories/snapshots/') | ||
username = findProperty('ossrhUsername') | ||
password = findProperty('ossrhPassword') | ||
} | ||
} | ||
} | ||
|
||
subprojects { | ||
def javaProjects = subprojects.findAll { !nonJavaProjects.contains(it.name) } | ||
configure(javaProjects) { | ||
apply plugin: 'java-library' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'idea' | ||
apply plugin: 'jacoco' | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
|
||
apply plugin: 'com.dorongold.task-tree' | ||
apply plugin: 'com.github.johnrengelman.shadow' | ||
apply plugin: 'com.github.sherter.google-java-format' | ||
apply plugin: 'net.ltgt.apt' | ||
|
||
group = 'com.google.api' | ||
|
||
sourceCompatibility = 1.8 | ||
targetCompatibility = 1.8 | ||
|
||
|
@@ -281,91 +279,93 @@ subprojects { | |
file('.factorypath') | ||
} | ||
} | ||
} | ||
|
||
// Publishing | ||
// ---------- | ||
def normalReleasableProjects = subprojects.findAll { | ||
!nonReleaseProjects.contains(it.name) && !noDefaultPublications.contains(it.name) | ||
} | ||
configure(normalReleasableProjects) { | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
|
||
afterEvaluate { | ||
if (!noDefaultPublications.contains(project.name)) { | ||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
version = project.version | ||
|
||
from components.java | ||
|
||
artifact javadocJar | ||
artifact sourcesJar | ||
artifact testlibJar | ||
|
||
pom { | ||
name = 'GAX (Google Api eXtensions) for Java' | ||
packaging = 'jar' | ||
artifactId = project.name | ||
description = 'Google Api eXtensions for Java' | ||
url = 'https://github.com/googleapis/gax-java' | ||
publishing { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes to the inside block of |
||
publications { | ||
mavenJava(MavenPublication) { | ||
version = project.version | ||
|
||
scm { | ||
url = 'https://github.com/googleapis/gax-java' | ||
connection = 'scm:git:https://github.com/googleapis/gax-java.git' | ||
} | ||
from components.java | ||
|
||
artifact javadocJar | ||
artifact sourcesJar | ||
artifact testlibJar | ||
|
||
pom { | ||
name = 'GAX (Google Api eXtensions) for Java' | ||
packaging = 'jar' | ||
artifactId = project.name | ||
description = 'Google Api eXtensions for Java' | ||
url = 'https://github.com/googleapis/gax-java' | ||
|
||
scm { | ||
url = 'https://github.com/googleapis/gax-java' | ||
connection = 'scm:git:https://github.com/googleapis/gax-java.git' | ||
} | ||
|
||
licenses { | ||
license { | ||
name = 'BSD' | ||
url = 'https://github.com/googleapis/gax-java/blob/master/LICENSE' | ||
} | ||
licenses { | ||
license { | ||
name = 'BSD' | ||
url = 'https://github.com/googleapis/gax-java/blob/master/LICENSE' | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id = 'GoogleAPIs' | ||
name = 'GoogleAPIs' | ||
email = 'googleapis@googlegroups.com' | ||
url = 'https://github.com/googleapis/gax-java' | ||
organization = 'Google LLC' | ||
organizationUrl = 'https://www.google.com' | ||
} | ||
developers { | ||
developer { | ||
id = 'GoogleAPIs' | ||
name = 'GoogleAPIs' | ||
email = 'googleapis@googlegroups.com' | ||
url = 'https://github.com/googleapis/gax-java' | ||
organization = 'Google LLC' | ||
organizationUrl = 'https://www.google.com' | ||
} | ||
} | ||
} | ||
} | ||
repositories { | ||
maven { | ||
url 'https://google.oss.sonatype.org/service/local/staging/deploy/maven2/' | ||
credentials { | ||
username = project.findProperty('ossrhUsername') | ||
password = project.findProperty('ossrhPassword') | ||
} | ||
} | ||
repositories { | ||
maven { | ||
url 'https://google.oss.sonatype.org/service/local/staging/deploy/maven2/' | ||
credentials { | ||
username = findProperty('ossrhUsername') | ||
password = findProperty('ossrhPassword') | ||
} | ||
} | ||
} | ||
} | ||
|
||
task checkJavaLinkage(type: JavaExec) { | ||
// Example invocation: | ||
// ./gradlew gax-httpjson:checkJavaLinkage | ||
dependsOn project.getTasksByName('publishMavenJavaPublicationToMavenLocal', true) | ||
classpath = configurations.linkageChecker | ||
main = 'com.google.cloud.tools.opensource.classpath.LinkageCheckerMain' | ||
|
||
def arguments = ['-a', "com.google.api:${project.name}:${project.version}"] | ||
if (project.name == 'gax-grpc') { | ||
// The exclusion file can be regenerated by '-o' option. See its Wiki for details: | ||
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/LinkageCheckerMain#exclusion-files | ||
arguments += ['--exclusion-file', 'linkage-checker-exclusion.xml'] | ||
} | ||
args arguments | ||
task checkJavaLinkage(type: JavaExec) { | ||
// Example invocation: | ||
// ./gradlew gax-httpjson:checkJavaLinkage | ||
dependsOn project.getTasksByName('publishMavenJavaPublicationToMavenLocal', true) | ||
classpath = configurations.linkageChecker | ||
main = 'com.google.cloud.tools.opensource.classpath.LinkageCheckerMain' | ||
|
||
def arguments = ['-a', "com.google.api:${project.name}:${project.version}"] | ||
if (project.name == 'gax-grpc') { | ||
// The exclusion file can be regenerated by '-o' option. See its Wiki for details: | ||
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/LinkageCheckerMain#exclusion-files | ||
arguments += ['--exclusion-file', 'linkage-checker-exclusion.xml'] | ||
} | ||
args arguments | ||
} | ||
} | ||
|
||
signing { | ||
if (!project.hasProperty('skip.signing') && !noDefaultPublications.contains(project.name)) { | ||
if (project.hasProperty('signing.gnupg.executable')) { | ||
useGpgCmd() | ||
} | ||
sign publishing.publications.mavenJava | ||
} | ||
signing { | ||
required { gradle.taskGraph.hasTask ":${name}:publishToSonatype" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
if (project.hasProperty('signing.gnupg.executable')) { | ||
useGpgCmd() | ||
} | ||
sign publishing.publications | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
plugins { | ||
id 'maven-publish' | ||
id 'signing' | ||
} | ||
|
||
archivesBaseName = 'gax-bom' | ||
|
||
project.version = "2.6.1-SNAPSHOT" // {x-version-update:gax-bom:current} | ||
|
||
ext { | ||
mavenJavaDir = "$buildDir/publications/mavenJava" | ||
mavenJavaBomOutputFile = file(mavenJavaDir + "/pom-default.xml") | ||
mavenJavaBomAscOutputFile = file(mavenJavaDir + "/pom-default.xml.asc") | ||
} | ||
def mavenJavaDir = "$buildDir/publications/mavenJava" | ||
def mavenJavaBomOutputFile = file(mavenJavaDir + '/pom-default.xml') | ||
def mavenJavaBomAscOutputFile = file(mavenJavaDir + '/pom-default.xml.asc') | ||
|
||
// Copy our pom.xml to the location where a generated POM would go | ||
task copyPom() { | ||
|
@@ -20,8 +23,6 @@ task copyPom() { | |
} | ||
} | ||
|
||
assemble.dependsOn copyPom | ||
|
||
// We want to use our own pom.xml instead of the generated one, so we disable | ||
// the pom.xml generation and have the publish tasks depend on `copyPom` instead. | ||
tasks.whenTaskAdded { task -> | ||
|
@@ -36,66 +37,45 @@ tasks.whenTaskAdded { task -> | |
} | ||
} | ||
|
||
jar.enabled = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not applying |
||
|
||
// Remove the default jar archive which is added by the 'java' plugin. | ||
// We could avoid this by not applying the 'java' plugin to all submodules of | ||
// gax, but that would create a little bit of a mess, so we hack around it here. | ||
configurations.archives.artifacts.with { archives -> | ||
def artifacts = [] | ||
archives.each { | ||
if (it.file =~ 'jar') { | ||
// We can't just call `archives.remove(it)` here because it triggers | ||
// a `ConcurrentModificationException`, so we add matching artifacts | ||
// to another list, then remove those elements outside of this iteration. | ||
artifacts.add(it) | ||
// We can't use the `publishing` section from the main build.gradle because | ||
// we don't want all the Java artifacts, and we want to use our own pom.xml | ||
// instead of the generated one. | ||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
version = project.version | ||
artifact mavenJavaBomOutputFile | ||
} | ||
} | ||
artifacts.each { | ||
archives.remove(it) | ||
repositories { | ||
maven { | ||
url 'https://google.oss.sonatype.org/service/local/staging/deploy/maven2/' | ||
credentials { | ||
username = findProperty('ossrhUsername') | ||
password = findProperty('ossrhPassword') | ||
} | ||
} | ||
} | ||
} | ||
|
||
artifacts { | ||
archives(mavenJavaBomOutputFile) { | ||
builtBy copyPom | ||
signing { | ||
required { gradle.taskGraph.hasTask ":${name}:publishToSonatype" } | ||
if (project.hasProperty('signing.gnupg.executable')) { | ||
useGpgCmd() | ||
} | ||
sign publishing.publications | ||
} | ||
|
||
afterEvaluate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need this anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't. Now everything inside the block is usable and available. We don't need to wait until the project is evaluated. |
||
// We can't use the `publishing` section from the main build.gradle because | ||
// we don't want all the Java artifacts, and we want to use our own pom.xml | ||
// instead of the generated one. | ||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
version = project.version | ||
artifact mavenJavaBomOutputFile | ||
} | ||
} | ||
repositories { | ||
maven { | ||
url 'https://google.oss.sonatype.org/service/local/staging/deploy/maven2/' | ||
credentials { | ||
username = project.findProperty('ossrhUsername') | ||
password = project.findProperty('ossrhPassword') | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
if (!project.hasProperty('skip.signing')) { | ||
if (project.hasProperty('signing.gnupg.executable')) { | ||
useGpgCmd() | ||
} | ||
sign publishing.publications.mavenJava | ||
|
||
publishing.publications.mavenJava(MavenPublication) { | ||
artifact(mavenJavaBomAscOutputFile) { | ||
extension 'pom.asc' | ||
} | ||
} | ||
// Unlike other regular subprojects, pom.asc (signature file) generated by | ||
// signing is not automatically picked up. It may be because gax-bom uses a | ||
// pre-written pom.xml instead of using an auto-generated one. | ||
// https://discuss.gradle.org/t/how-to-publish-artifacts-signatures-asc-files-using-maven-publish-plugin/7422 | ||
task addPomAscFileToPublication { | ||
onlyIf { mavenJavaBomAscOutputFile.exists() } | ||
doLast { | ||
publishing.publications.mavenJava(MavenPublication) { | ||
artifact(mavenJavaBomAscOutputFile) { extension 'pom.asc' } | ||
} | ||
} | ||
} | ||
signMavenJavaPublication.finalizedBy addPomAscFileToPublication |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense. As this is the root
build.gradle
,project.name
is alwaysgax-java
. And it's correct to configurenexusPublishing
in the root.