-
Notifications
You must be signed in to change notification settings - Fork 597
Gradle Build Scripts
Collapse
-
Declares the configuration required to instantiate and configure the hierarchy of
Project
instances which are to participate in a build. -
There is a one-to-one correspondence between a
Settings
instance and asettings.gradle
settings file. Before Gradle assembles the projects for a build, it creates aSettings
instance and executes the settings file against it. -
Open Liberty's
settings.gradle
file loads properties from either~/gradle.startup.properties
or it loads the property file passed as an option-Dbuild.properties.path
on an automated build. These are the expected properties (and typical values for a continuous integration build):
artifactory.download.server = eu.artifactory.swg-devops.com
artifactory.download.token = (token)
artifactory.download.user = [email protected]
artifactory.upload.server = na.artifactory.swg-devops.com
artifactory.upload.token = (token)
artifactory.upload.user = [email protected]
buildLabel = 20190704-1647
buildResultUUID = _VAzRUJ5xEemn7JSbMpQERQ
dhe.password = (password)
dhe.user = [email protected]
disable.run.runUnitTests = false
ghe.build.type = Continuous
gradle-tasks.log = /home/jazz_build/_VAzRUJ5xEemn7JSbMpQERQ-EBC.PROD.WASRTC-BT4-001-00-00/jbe/build/open-liberty/dev/gradle-tasks.log
gradle.log = /home/jazz_build/_VAzRUJ5xEemn7JSbMpQERQ-EBC.PROD.WASRTC-BT4-001-00-00/jbe/build/open-liberty/dev/gradle.log
gradle.opts = --stacktrace
gradle.properties.output.path= /home/jazz_build/_VAzRUJ5xEemn7JSbMpQERQ-EBC.PROD.WASRTC-BT4-001-00-00/jbe/build.launch/pass-thru-gradle.properties
intranet.id = [email protected]
intranet.password = (password)
intranet.user = [email protected]
junit.report.zip = /home/jazz_build/_VAzRUJ5xEemn7JSbMpQERQ-EBC.PROD.WASRTC-BT4-001-00-00/jbe/build/open-liberty/dev/open-liberty.unitTest.results.zip
published.gradle.log = /home/jazz_build/_VAzRUJ5xEemn7JSbMpQERQ-EBC.PROD.WASRTC-BT4-001-00-00/jbe/build/open-liberty/dev/tmp/gradle.log
Other properties that may be included:
artifactory.force.external.repo = true
is.personal = true
is.continuous.build = true
is.release = true
buildLabelPrefix =
is.public.publishing = true
build.os.native.packages = true
openLibertyBuild.disable = true
dont.build.open.liberty = true
- Properties are loaded onto a
Properties
instance calledgradle.ext.userProps
. It is also referred to asgradle.userProps
in build scripts that use it. - If the build is not using Artifactory, it will download Gradle plugins from https://plugins.gradle.org/m2/ and the default values for repository properties are set to:
is.using.artifactory = false
fetch.oss.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = RemotePublic;releaseUrl=https://repo.maven.apache.org/maven2/;index=${build}/oss_dependencies.maven
fetch.oss.ibm.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = RemoteIBM;local=~/.ibmdhe/repository;releaseUrl=https://public.dhe.ibm.com/ibmdl/export/pub/software/olrepo/;index=${build}/oss_ibm.maven
fetch.ibm.java.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = DummyRepo
push.ibm.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = RemotePublish
- If all the expected Artifactory properties are set and
artifactory.force.external.repo
is false, the build configures itself to use Artifactory to download Gradle plugins and sets non-default values for the repository properties:
is.using.artifactory = true
fetch.oss.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = RemotePublic;local=~/.ibmartifactory/repository;releaseUrl=https://eu.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;snapshotUrl=https://eu.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;index=${build}/oss_dependencies.maven
fetch.oss.ibm.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = RemoteIBM;local=~/.ibmartifactory/repository;releaseUrl=https://eu.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;snapshotUrl=https://eu.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;index=${build}/oss_ibm.maven
fetch.ibm.java.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = IBMInternalJava;local=~/.ibmartifactory/repository;releaseUrl=https://eu.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;snapshotUrl=https://eu.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;index=${build}/ibm_java.maven
push.ibm.repository = aQute.bnd.repository.maven.provider.MavenBndRepository;name = RemotePublish;releaseUrl=https://na.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;snapshotUrl=https://na.artifactory.swg-devops.com/artifactory/wasliberty-open-liberty;index=${build}/openliberty.maven
1.1. wlp-gradle/propertiesSettings.gradle
:
- Additional properties are set to
gradle.ext.userProps
. The properties fromgenerated.properties
are set if the file exists. - If these properties were not already set, then they are set (with these default values):
is.automated.build = false
is.personal = false
is.continuous.build = false
is.release = false
is.public.publishing = false
disable.run.runUnitTests = false
build.os.native.packages = false
javac.bootclasspath.1.4 = (varies by environment)
javac.bootclasspath.1.6 = (varies by environment)
javac.bootclasspath.1.7 = (varies by environment)
javac.bootclasspath.1.8 = (varies by environment)
version.qualifier = (timestamp with the format yyyyHHddHHmm)
buildLabel = (timestamp with the format yyyyHHddHHmm)
- If the build is using Artifactory, then these properties are set with non-default values:
javac.bootclasspath.1.4 = ${internaljavac.bootclasspath.1.4}
javac.bootclasspath.1.6 = ${internaljavac.bootclasspath.1.6}
javac.bootclasspath.1.7 = ${internaljavac.bootclasspath.1.7}
javac.bootclasspath.1.8 = ${internaljavac.bootclasspath.1.8}
1.2. wlp-gradle/bndSettings.gradle
:
- This file is responsible for including all the
Project
instances to the Gradle build. Seeinclude
for more information on howProject
instances are added to the Gradle build. - First, it configures bnd plugin dependencies to the
bndSettings.gradle
build script androotProject
build script instances. That enablesbndSettings.gradle
to initialize using bnd classes androotProject
to apply thebiz.aQute.bnd
plugin to other projects. - Then it instantiates a
aQute.bnd.build.Workspace
instance and sets each property ingradle.userProps
to aProperties
instance on theWorkspace
. This is so we can use the properties in any.bnd
file in the workspace. Specifically, we heavily use the properties incnf/build.bnd
and other files included by that. More on these files soon. - Lastly, the "cnf" project is included in the Gradle build, along with "build.image", "wlp-bndPlugins", "wlp-rasInstrumentation", and any project returned by
workspace.getAllProjects()
. If a project returned byworkspace.getAllProjects()
includes a sub directory containing aspringboot.gradle
build script, that directory is included as a project in the Gradle build too. - The
Workspace
initialized here is namedrootProject.ext.bndWorkspace
, so anyProject
instance may reference it asrootProject.bndWorkspace
. - The collection of bnd project names is named
rootProject.ext.gradleBndProject
, soProject
instances that need to know about projects in the entire workspace may reference that asrootProject.gradleBndProject
.
1.2.1 cnf/build.bnd
- More to come.
1.3. wlp-gradle/buildCacheSettings.gradle
:
- The build cache stores
Task
outputs. The remote build cache (https://na.artifactory.swg-devops.com/artifactory/wasliberty-generic-local) is always enabled. If the build is not automated, the local build cache (~/.gradle/caches/build-cache-1
) is enabled. If it is a continuous integration build, newTask
outputs are pushed to the remote build cache.
Collapse
- There is a one-to-one relationship between a
Project
and abuild.gradle
file. TherootProject
is configured by thisbuild.gradle
file with the name "dev". Any project in the hierarchy can refer to it by therootProject
property. Because of this, we set some commonly used extra properties onto therootProject
.cnf
is a reference to theProject
named "cnf".buildImage
is a reference to theProject
named "build.image".storeProps
is a named function to write some of the properties determined at build time to a file namedgenerated.properties
for future builds. - Throughout the remainder of the configuration lifecycle phase, keep in mind that tasks may have
doFirst
ordoLast
code configured.doFirst
anddoLast
code will be configured, but not executed during this phase.
2.1. wlp-gradle/java.gradle
:
- Each sub project of the
rootProject
has thejava
plugin applied to it, adding many of the common development tasks to these projects. - This build script makes various configuration tweaks on tasks applied by the
java
plugin, such as test tasks are configured to ignore failures.JavaCompile
type tasks set source and target compatibility to "1.7" if they would have been build with "1.6" and the JVM is compatible with Java 12, and if the JVM is compatible with Java 9 or higher, they add a--release
argument to the compiler. Lastly,Javadoc
type tasks add aXdoclint:none
and-quiet
option if the JVM is compatible with Java 9. - The build script adds the
testReport
andtestResults
tasks to generate a HTML test report of all unit test results.
2.2. wlp-gradle/biz.aQute.bnd.gradle
:
- This build script is responsible for applying plugins to bnd Projects (or projects that have a
.bnd
file). That is determined by selecting projects for whichbndWorkspace.getProject(name)
does not return null. - First, the
biz.aQute.bnd
plugin is applied. Doing that addsrelease
,releaseNeeded
and several other development tasks commonly used in the build. - Next, the build scripts in
wlp-gradle/subprojects
are applied as described below. - Lastly, if a bnd Project does not have the bnd properties
fat.project
andtest.project
set to true, and does not set-nobundles
, then it is considered a runtime project and thenet.ossindex.audit
plugin is applied, causing the theaudit
task to be added.
2.2.1. wlp-gradle/subprojects/repos.gradle
- This build script configures a Maven repository for Artifactory if
is.using.artifactory
is set to true. Otherwise, Maven Central and https://public.dhe.ibm.com/ibmdl/export/pub/software/olrepo/ are used to download project dependencies. The script does not fall back to Maven Central and IBM DHE when there are Artifactory outages.
2.2.2. wlp-gradle/subprojects/publish.gradle
- Applies the
maven-publish
plugin, which allows the use ofpublishing
blocks and thepublish
development task, so projects' build scripts can declare additional artifacts to upload into the localcnf/release
Maven repository.
2.2.3. wlp-gradle/subprojects/anttaskdefs.gradle
- This build script runs
ant.taskdef
for several Ant tasks built in the workspace so that they can be used by Gradle tasks.
2.2.4. wlp-gradle/subprojects/tasks.gradle
- Configure 'globalize', 'copyPiiFiles', 'verifyBundleNLS', 'compileJava', 'test', 'apiSpiJavadoc', and 'zipJavadoc' tasks.
2.2.5. wlp-gradle/subprojects/jacoco.gradle
- This build script applies the
Jacoco
plugin, which adds thejacocoTestReport
task, and that is configured to depend ontest
tasks and generate an HTML report.
2.2.6. wlp-gradle/subprojects/assemble.gradle
- Create 'publishWLPJars', 'publishJavadoc', 'publishToolScripts', 'publishToolJars', 'publishSchemaResources', 'publishPlatformManifests', 'publishPlatformFiles', 'publishTemplates', 'publishBinScripts', 'publishClientScripts', and 'publishLibNative' tasks. Configure 'assemble' to depend on above tasks.
2.2.7. wlp-gradle/subprojects/fat.gradle
- Configure 'buildfat', 'runfat', 'buildandrun', and 'cleanFat' tasks on FAT projects.
Collapse
-
When the build reaches a task to execute, it runs
doFirst
code, executes, then runsdoLast
code. -
The build executes tasks in the order they were configured by the plugin's defaults and then the task's
dependsOn
property. The build skips executingUP-TO-DATE
,FROM-CACHE
, andSKIPPED
tasks.-
UP-TO-DATE
andFROM-CACHE
tasks are determined by theinputs
andoutputs
of a task. These inputs/outputs can be files or properties. If theinputs
andoutputs
have same hash values as stored in~/.gradle/caches
or a remote Gradle cache, then the tasks will be markedFROM-CACHE
. If the outputs are already built, the tasks will be markedUP-TO-DATE
. -
SKIPPED
tasks are determined by a task'senabled
property. If the property evaluates to false, the task is skipped.
-
- [project:]taskName - TaskType
- Depends on: List of tasks this task depends on
- Description of this task.
- cnf:initialize
- Depends on: cleanRepos, copyMavenLibs, and updatePluginClasses
- Aggregate task that deletes "cnf/release", "cnf/release.mvn", "cnf/local", and "cnf/local.mvn", copies several libraries into "cnf/mavenlibs", and builds "wlp-bndPlugins" into "cnf/bndplugins/classes" and refreshes the bnd Project instances.
- This must be run once after a clone, clean, or checking out a new branch.
Figure 1. Java plugin - tasks
- compileJava - JavaCompile
- Depends on: All tasks which contribute to the compilation classpath, including jar tasks from projects that are on the classpath via project dependencies
- Compiles production Java source files using the JDK compiler.
- jar - Jar
- Depends on: classes
- Assembles the production JAR file, based on the classes and resources attached to the main source set.
- javadoc - Javadoc
- Depends on: classes
- Generates API documentation for the production Java source using Javadoc.
- compileTestJava - JavaCompile
- Depends on: classes, and all tasks that contribute to the test compilation classpath
- Compiles test Java source files using the JDK compiler.
- test - Test
- Depends on: testClasses, and all tasks which produce the test runtime classpath
- Runs the unit tests using JUnit or TestNG.
- testReport - TestReport
- Depends on: test tasks of all subprojects included in the build
- Generates an HTML test report from the results of one or more Test tasks.
- testResults
- Depends on: testReport, and test tasks of all subprojects
- Aggregate task to create a test report for all subprojects.
- assemble
- Depends on: jar, and all other tasks that create artifacts attached to the archives configuration
- Aggregate task that assembles all the archives in the project. This task is added by the Base Plugin — which the Java Plugin applies automatically.
- jacocoTestReport - JacocoReport
- Depends on: test
- Task to generate HTML, Xml and CSV reports of Jacoco coverage data.
- audit
- Audits a gradle project using the OSS Index REST API v3 to identify known vulnerabilities in its dependencies.
- publish
- Depends on: All publishPubNamePublicationToRepoNameRepository tasks
- An aggregate task that publishes all defined publications to all defined repositories. It does not include copying publications to the local Maven cache.
- release
- Depends on: jar, and all other tasks that create artifacts attached to the archives configuration
- Releases the project's bundles to the -releaserepo, if one is configured for the project.
- releaseNeeded
- Depends on: jar, and all other tasks that create artifacts attached to the archives configuration
- Releases the project and all projects it depends on.
- bndproperties
- Display the Bnd properties of the project.
- cleanFat - Delete
- Deletes the build/autoFVT directory of a project.
- buildfat
- Depends on: cleanFat, assemble, build, zipProjectFVT
- Aggregate task that deletes the build/autoFVT directory of a project, assembles, builds, and creates a zip of the project's autoFVT bucket.
- runfat - Exec
- Depends on: cleanBeforeRun
- Aggregate task that assembles all the archives in the project. This task is added by the Base Plugin — which the Java Plugin applies automatically.
- buildandrun
- Depends on: buildfat, runfat
- Aggregate task that runs builds and runs a FAT.
copyMavenLibs - Copy
updatePluginClasses - Copy
cleanRepos - Delete
everythingElseHasBeenReleased
createGradleBootstrap
createESALists
createGeneratedReplacementProjects
index - Index
createIndex
zipGradleBootstrap - Zip
libertyReleaseVersions
printProjectDependencies
checkForUpdates
updateArtifact
globalize
copyPiiFiles - Copy
verifyBundleNLS
publishWLPJars - Copy
apiSpiJavadoc - Javadoc
zipJavadoc - Zip
publishJavadoc - Copy
publishToolScripts - Copy
publishToolJars - Copy
publishSchemaResources - Copy
publishPlatformManifests - Copy
publishPlatformFiles - Copy
publishTemplates - Copy
publishBinScripts - Copy
publishClientScripts - Copy
publishLibNative - Copy
cleanBeforeRun - Delete
addRequiredLibraries - Copy
addDerby - Copy
copyFeatureBundles
autoFVT
zipAutoFVT - Zip
zipProjectFVT - Zip
copyPropertiesToBuildImage - Copy
copyReadmeToBuildImage - Copy
copyLicenseToBuildImage - Copy
copySwidTagToBuildImage - Copy
packageOpenLiberty - PackageLibertyWithFeatures
packageOpenLibertyKernel - PackageLibertyWithFeatures
packageOpenLibertyWebProfile8 - PackageLibertyWithFeatures
packageOpenLibertyJavaee8 - PackageLibertyWithFeatures
packageOpenLibertyMicroProfile2 - PackageLibertyWithFeatures
packageOpenLibertyMicroProfile3 - PackageLibertyWithFeatures
zipOpenLiberty - Zip
zipOpenLibertyKernel - Zip
zipOpenLibertyWebProfile8 - Zip
zipOpenLibertyJavaee8 - Zip
zipOpenLibertyMicroProfile2 - Zip
zipOpenLibertyMicroProfile3 - Zip
zipOpenLibertyAll - Zip
createOLRuntimePoms
zipOpenLibertyMaven - Zip
zipTestReport - Zip
createJSONForPublicArtifacts
gatherTestResults
copyOpenLiberty - Copy
updateSpecTemplate - Copy
updateChangelogTemplate - Copy
updateBuildPackageScriptTemplate - Copy
updateRulesTemplate - Copy
buildOsNativePackages - Exec
help
tasks [--all]
wrapper
properties
model