Skip to content

Commit

Permalink
Move to unified gradle build
Browse files Browse the repository at this point in the history
- also upgrades gradle to 5.2.1
- all builds should happen from root :<project>:<task>
- install task is replaced by publishToMavenLocal for local testing
  • Loading branch information
loosebazooka committed Jul 26, 2019
1 parent 6ebc11c commit 22e38b8
Show file tree
Hide file tree
Showing 51 changed files with 512 additions and 1,974 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ env:

install: true
script:
- (cd jib-core; ./gradlew --stacktrace build)
- (cd jib-plugins-common; ./gradlew --stacktrace build)
- (cd jib-gradle-plugin; ./gradlew --stacktrace build)
# unset _JAVA_OPTIONS to avoid spurious test failures
- (cd jib-maven-plugin; unset _JAVA_OPTIONS; ./mvnw -B verify -U)
- ./gradlew clean build --stacktrace

# cobbled together from
# https://docs.travis-ci.com/user/languages/java/#projects-using-gradle
Expand Down
314 changes: 314 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
// define all versioned plugins here and apply in subprojects as necessary without version
plugins {
id 'com.github.sherter.google-java-format' version '0.8' apply false
id 'net.ltgt.apt' version '0.19' apply false
id 'net.ltgt.errorprone' version '0.6' apply false
id 'net.researchgate.release' version '2.7.0' apply false
id 'com.gradle.plugin-publish' version '0.10.1' apply false
id 'io.freefair.maven-plugin' version '3.8.1' apply false
}

import net.ltgt.gradle.errorprone.CheckSeverity

subprojects {
group 'com.google.cloud.tools'

repositories {
mavenCentral()
}

apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'net.ltgt.apt'
apply plugin: 'net.ltgt.errorprone'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding = 'UTF-8'

/* PROJECT DEPENDENCY CONTRAINTS */
// define all versioned dependencies here and apply in subprojects as necessary without version
dependencies {
constraints {
implementation 'com.google.http-client:google-http-client:1.27.0'
implementation 'org.apache.commons:commons-compress:1.18'
implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9.1'
implementation 'org.ow2.asm:asm:7.0'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.4'
testImplementation 'org.slf4j:slf4j-api:1.7.25'
}
}
/* PROJECT DEPENDENCY CONTRAINTS */

/* NULLAWAY */
dependencies {
// NullAway errorprone plugin
annotationProcessor 'com.uber.nullaway:nullaway:0.6.4'
errorprone 'com.google.errorprone:error_prone_core:2.3.2'
// Using github.com/google/error-prone-javac is required when running on
// JDK 8. Remove when migrating to JDK 11.
if (System.getProperty("java.version").startsWith("1.8.")) {
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}
}

// Adds NullAway errorprone checks.
tasks.withType(JavaCompile) {
if (!name.toLowerCase().contains("test")) {
options.errorprone {
check('NullAway', CheckSeverity.ERROR)
option('NullAway:ExcludedFieldAnnotations', 'org.apache.maven.plugins.annotations.Component')
option('NullAway:AnnotatedPackages', 'com.google.cloud.tools')
}
}
}
/* NULLAWAY */

/* GOOGLE JAVA FORMAT */
googleJavaFormat {
toolVersion = '1.6'
}
check.dependsOn verifyGoogleJavaFormat
/* GOOGLE JAVA FORMAT */

/* CHECKSTYLE */
checkstyle {
toolVersion = '8.18'

// get the google_checks.xml file from the checkstyle jar and take out the java checks
def googleChecks = resources.text.fromArchiveEntry(configurations.checkstyle[0], 'google_checks.xml').asString()
def fileExtensionsBefore = '<property name="fileExtensions" value="java, properties, xml"/>'
def fileExtensionsAfter = '<property name="fileExtensions" value="properties, xml"/>'
def googleChecksNoJava = googleChecks.replace(fileExtensionsBefore, fileExtensionsAfter)
assert !googleChecks.equals(googleChecksNoJava)

config = resources.text.fromString(googleChecksNoJava)

maxErrors = 0
maxWarnings = 0
}
/* CHECKSTYLE */

/* TEST CONFIG */
tasks.withType(Test) {
reports.html.setDestination file("${reporting.baseDir}/${name}")
}

test {
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
}
// jar to export tests classes for import in other project by doing:
// testCompile project(path:':project-name', configuration:'tests')
task testJar(type: Jar) {
from sourceSets.test.output.classesDirs
classifier = 'tests'
}
// to import resources do: sourceSets.test.resources.srcDirs project(':project-name').sourceSets.test.resources

configurations {
tests
}

artifacts {
tests testJar
}
/* TEST CONFIG */

/* INTEGRATION TESTS */
sourceSets {
integrationTest {
java.srcDir file('src/integration-test/java')
resources.srcDir file('src/integration-test/resources')
}
}

configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntime
}

dependencies {
integrationTestImplementation sourceSets.main.output
integrationTestImplementation sourceSets.test.output
integrationTestImplementation configurations.compile
integrationTestImplementation configurations.testImplementation
integrationTestImplementation configurations.runtime
integrationTestImplementation configurations.testRuntime
}

// Integration tests must be run explicitly
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
systemProperty '_JIB_DISABLE_USER_AGENT', true
}
integrationTest.dependsOn test

task integrationTestJar(type: Jar) {
from sourceSets.integrationTest.output.classesDirs
classifier = 'integration-tests'
}

configurations {
integrationTests
}

artifacts {
integrationTests integrationTestJar
}
/* INTEGRATION TESTS */

/* JAVADOC ENFORCEMENT */
// Fail build on javadoc warnings
tasks.withType(Javadoc) {
options.addBooleanOption('Xwerror', true)
}
assemble.dependsOn javadoc
/* JAVADOC ENFORCEMENT */

/* JAR */
// optional release configuration (call these methods in subprojects)
jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion
}
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier 'sources'
}

task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
classifier 'javadoc'
}
/* JAR */

/* RELEASE */
project.ext.configurePomProperties = { // must be called in subproject ConfigurePomProperties()
publishing {
publications {
mavenJava(MavenPublication) {
pom {
// to be filled by subproject
// name = ''
// description = ''

url = 'https://github.com/GoogleContainerTools/jib'
inceptionYear = '2018'

licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
developers {
developer {
id = 'chanseokoh'
name = 'Chanseok Oh'
email = 'chanseok@google.com'
}
developer {
id = 'loosebazooka'
name = 'Appu Goundan'
email = 'appu@google.com'
}
developer {
id = 'TadCordle'
name = 'Tad Cordle'
email = 'tcordle@google.com'
}
developer {
id = 'briandealwis'
name = 'Brian de Alwis'
email = 'bdealwis@google.com'
}
developer {
id = 'coollog'
name = 'Qingyang Chen'
}
}
scm {
url = 'https://github.com/GoogleContainerTools/jib'
connection = 'scm:https://github.com/GoogleContainerTools/jib.git'
developerConnection = 'scm:git://github.com/GoogleContainerTools/jib.git'
}
}
}
}
}
generatePomFileForMavenJavaPublication {
destination = file("${project.buildDir}/pom/${project.name}-${project.version}.pom")
}
}

project.ext.configureReleaseTask = { // must be called in subproject configureReleaseTask()
// For kokoro sign and release
task prepareRelease(type: Copy) {
from jar
from sourceJar
from javadocJar
from generatePomFileForMavenJavaPublication
into "${project.buildDir}/release-artifacts"
dependsOn build
dependsOn cleanPrepareRelease
}
}

/* RELEASE */

/* INCLUDED PROJECT DEPENDENCY HELPER */
// to keep track of all source projects
project.ext.sourceProjects = []
// sourceProject(Project) accepts a project and adds it as a dependency in a special manner:
// 1. add the project classes as "compileOnly" and make it available to tests in "testImplementation"
// 2. add the project's depedencies as "implementation"
// 3. remove any transitive reference of any sourceProject depenency that may have appeared
// 4. add the project's classes to the final jar
// Other nice effects (vs shadowJar)
// 1. Generated poms will be correct
// 2. Configuration is isolated to this single "sourceProject" call
// 3. These configurations are compliant with IDEs
project.ext.sourceProject = { Project dependencyProject ->
def dependencyProjectClasses = dependencyProject.sourceSets.main.output
dependencies {
// add the dependencyProject classes as compileOnly, make it available to tests
compileOnly dependencyProjectClasses
testImplementation dependencyProjectClasses
// add dependencyProject's dependencies as implementation dependencies
implementation dependencyProject.configurations.implementation.dependencies
if (dependencyProject.configurations.hasProperty('api')) {
implementation dependencyProject.configurations.api.dependencies
}
// if we find any project dependencies that are brought in transitively, go remove them
project.sourceProjects.each { projectToRemove ->
project.configurations.implementation.dependencies.remove projectToRemove
}
}
// keep track of all dependencyProjects for later removal
sourceProjects += dependencyProject
// adds dependencyProject's classes to jar (fat jar-esque)
jar {
from dependencyProjectClasses
}
// also configure the java-gradle-plugin if necessary
if (project.hasProperty("gradlePlugin")) {
project.tasks.pluginUnderTestMetadata.pluginClasspath.from dependencyProjectClasses
}
}
/* INCLUDED PROJECT DEPENDENCY HELPER */
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion jib-gradle-plugin/gradlew → gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
2 changes: 1 addition & 1 deletion jib-gradle-plugin/gradlew.bat → gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
Loading

0 comments on commit 22e38b8

Please sign in to comment.