Gradle for v8.4 - tooltwist/documentation GitHub Wiki
Gradle configuration at Twist Resources
As discuss here, we use two repositories - one that is cloud based, and a local cache server to speed up builds. We publish to the cloud based server, but resolve artifacts (jars, etc) during builds from the local server, which is located in the office.
gradle.properties
For example:
#
# PLEASE NOTE:
#
# The Gradle build also uses ARTIFACTORY_USER and ARTIFACTORY_PASSWORD,
# but DO NOT define them here of they will be saved into version control
# where anyone can see them.
#
PROJECT_SOURCE_COMPATIBILITY=1.7
PROJECT_GROUP=com.tooltwist
# Make sure either both are snapshot, or neither are snapshot versions.
PROJECT_VERSION=5.0.0-SNAPSHOT
TOOLTWIST_VERSION=8.3.3-SNAPSHOT
# Properties related to publishing this project's artifacts
PUBLISH_CONTEXTURL=http\://repo.tooltwist.com/artifactory/
PUBLISH_SNAPSHOT_REPO=rpdata-snapshot-local
PUBLISH_RELEASE_REPO=rpdata-release-local
~/.gradle/gradle.properties
This file is specific to a particular developer, and is not checked into version control.
We define the user credentials here because it is not saved to Github, and we define the resolving repo so all projects can be defined in a single place.
[email protected]
ARTIFACTORY_PASSWORD={DESede}xxxxxxxxxxxxxxxxxxxxxx==
RESOLVE_CONTEXTURL=http\://officerepo.local:8081/artifactory/
RESOLVE_REPO=office-all-in-one
settings.gradle
The setting.gradle
file is often forgotten.
Simple Projects:
For most projects it is a good idea to create an empty file named settings.gradle
in the project directory. This will prevent Gradle from scanning the directory hierarchy to see if the project is a compound project.
Compound Projects:
If you have an application where you are working on the source of multiple Eclipse projects at the same time, you can define them to Gradle of sub-projects of a single root project using the instructions at Compound Gradle Projects.
build.gradle
This file is mostly boilerplate.
The header is constant. Do not change this:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'artifactory'
apply plugin: 'maven' // so a POM file can be uploaded to repo
task sourceJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourceJar
}
//----------------------------------------------------------------------
// Gradle lacks the "provided" dependency so we'll have to add it.
// http://blog.codeaholics.org/2012/emulating-mavens-provided-scope-in-gradle/
configurations {
provided
published
}
sourceSets {
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
//----------------------------------------------------------------------
The middle is application specific. Do change this:
dependencies {
/* ToolTwist Dependencies
compile group: 'com.tooltwist', name: 'ttWbd', version: TOOLTWIST_VERSION
// Project dependencies
/* example only */
compile group: 'net.sourceforge.htmlcleaner', name: 'htmlcleaner', version: '2.2'
compile group: 'org.xhtmlrenderer', name: 'core-renderer', version: 'R8pre2'
compile group: 'org.json', name: 'json', version: '20140107'
// This jar contains stubs used only while compiling. At runtime the
// web server (e.g. Tomcat) provides the real implementation of the API.
provided 'javax:javaee-api:6.0'
// Used only during unit testing
testCompile group: 'junit', name: 'junit', version: '4.8.2'
}
And from here on down is also standard. Do not change this:
/**************************************************************************************************
*
* NOTE: Standard code from here on down. (Phil-2014-06-03)
*
* Values defined in ../gradle.properties:
* PROJECT_GROUP, PROJECT_SOURCE_COMPATIBILITY, PROJECT_VERSION, PROJECT_REPO
*
* Values defined in ~/.gradle/gradle.properties:
* artifactory_user, artifactory_password, artifactory_repo
*/
group = PROJECT_GROUP
version = PROJECT_VERSION
sourceCompatibility = PROJECT_SOURCE_COMPATIBILITY
// Remember whether this is a snapshot or release, so we publish to the correct repository.
project.ext.isSnapshot = version.endsWith("-SNAPSHOT")
// Include jars for the artifactory plugin
buildscript {
repositories {
maven { url 'http://jcenter.bintray.com' }
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
configurations {
published
}
artifactory {
publish {
repository {
contextUrl = "${PUBLISH_CONTEXTURL}"
repoKey = isSnapshot ? "${PUBLISH_SNAPSHOT_REPO}" : "${PUBLISH_RELEASE_REPO}"
username = "${ARTIFACTORY_USER}"
password = "${ARTIFACTORY_PASSWORD}"
maven = true
ivy {
ivyLayout = '[organization]/[module]/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
mavenCompatible = true
}
}
defaults {
publishConfigs('archives', 'published')
properties = ['build.status': "$it.project.status".toString()]
}
}
resolve {
repository {
contextUrl = "${RESOLVE_CONTEXTURL}"
repoKey = "${RESOLVE_REPO}"
username = "${ARTIFACTORY_USER}"
password = "${ARTIFACTORY_PASSWORD}"
maven = true
}
}
}
// Note that tests only get run when the code changes
test {
testLogging {
// Show that tests are run in the command-line output
events "passed", "skipped", "failed"
}
}
// The Gradle wrapper allows building without Gradle installed
// See http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
/*
* If we're reconfiguring Eclipse, take the opportunity to fix the occasional
* problem where 'Deployment Assembly' is missing from the properties dialog,
* preventing dependency jars from being added to the War and Tomcat classpath.
* http://forums.gradle.org/gradle/topics/my_war_in_eclipse_doesnt_see_jars_in_other_projects
*/
eclipse {
project {
natures 'org.eclipse.wst.common.modulecore.ModuleCoreNature'
}
}
/**************************************************************************************************
*
* Copy various resources into the jar file or into separate zip files.
*/
task copyWebContent(type: Copy) {
from('WebContent')
into 'build/classes/main/META-INF/resources'
}
task copyConfig(type: Copy) {
from('config')
into 'build/classes/main/META-INF/tooltwist/config'
}
task copyWidgets(type: Copy) {
from('widgets')
into 'build/classes/main/META-INF/tooltwist/widgets'
}
task configZip(type: Zip) {
from 'config'
classifier = "tooltwist-config"
}
task widgetsZip(type: Zip) {
from 'widgets'
classifier = "tooltwist-widgets"
}
task webcontentZip(type: Zip) {
from 'WebContent'
classifier = "tooltwist-webcontent"
}
processResources {
// Maybe place resources directly inside the jar file.
if (project.hasProperty('PROJECT_DIRECTORIES_IN_JAR') && PROJECT_DIRECTORIES_IN_JAR.toBoolean()) {
println "Including config, widgets and WebContent inside jar file"
processResources.dependsOn("copyWebContent")
processResources.dependsOn("copyConfig")
processResources.dependsOn("copyWidgets")
}
// Create zip files for config, widget and WebContent.
if (file('config').isDirectory()) {
processResources.dependsOn("configZip")
project.artifacts { archives configZip }
}
if (file('widgets').isDirectory()) {
processResources.dependsOn("widgetsZip")
project.artifacts { archives widgetsZip }
}
if (file('WebContent').isDirectory()) {
processResources.dependsOn("webcontentZip")
project.artifacts { archives webcontentZip }
}
}
Importing the Gradle Definition into Eclipse
Work in progress...