Example build.gradle - tooltwist/documentation GitHub Wiki
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'artifactory'
apply plugin: 'maven' // so a POM file can be uploaded to repo
/*
* Gradle lacks a "provided" dependency like Maven, so we have to
* add it. For example, we wish to specify that the J2EE API is
* provided by the runtime, so the mock API jar we use here is
* used for compiling but is not carried forward as a dependency
* through into production.
*
* 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
main { resources { srcDir 'src' } }
}
/*
* This section contains you project dependencies.
*/
dependencies {
// ToolTwist Dependencies
compile 'com.tooltwist:ttWbd:8.3.3-SNAPSHOT'
// Hack - extras, to ensure they end up in ttsvr
compile 'com.tooltwist:ttStd:8.3.2'
compile 'com.tooltwist:ttsec-standaloneDesigner:8.3.2'
/* Dependency on another project of mine */
compile 'com.tooltwist:myOtherProject:1.2.3-SNAPSHOT'
/* Dependency if you have source code installed.
compile project(':myOtherProject')
*/
/*
* Insert your dependencies here.
* |
* |
* V
*/
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Equivalent definitions (examples only - replace these with your own)
compile 'org.apache.axis2:axis2:1.5.4'
compile group: 'org.apache.axis2', name: 'axis2', version: '1.5.4'
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Logging using slf4j
compile group: 'ch.qos.logback', name: 'logback-core', version: '0.9.30'
compile group: 'ch.qos.logback', name: 'logback-classic', version:'0.9.30'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.2'
// 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'
}
/***************************************************************************
*
* NOTE: Standard code from here on down.
*
* (Properties are defined in ~/.gradle/gradle.properties)
*/
group = MYPROJECT_GROUP
version = MYPROJECT_VERSION
sourceCompatibility = MYPROJECT_SOURCE_COMPATIBILITY
/*
* Save a source code jar file when publishing into the repo.
*/
task sourceJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourceJar
}
/*
* Define dependencies to be used by Gradle (not the project).
* In particular, include the jar for artifactory.
*/
buildscript {
repositories {
maven {
url TOOLTWIST_ARTIFACTORY_CONTEXTURL + TOOLTWIST_ARTIFACTORY_REPO
credentials {
username = "${TOOLTWIST_ARTIFACTORY_USER}"
password = "${TOOLTWIST_ARTIFACTORY_PASSWORD}"
}
}
mavenCentral()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
/*
* Tell the artifactory plugin where to find jars when building, and
* where to publish them.
*
* https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin
*/
project.ext.isSnapshot = version.endsWith("-SNAPSHOT")
artifactory {
publish {
repository {
contextUrl = "${PUNDIT_PUBLISH_ARTIFACTORY_CONTEXTURL}"
repoKey = isSnapshot ? "${PUNDIT_PUBLISH_SNAPSHOT_REPO}" : "${PUNDIT_PUBLISH_RELEASE_REPO}"
username = "${PUNDIT_PUBLISH_USER}"
password = "${PUNDIT_PUBLISH_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_ARTIFACTORY_CONTEXTURL}"
repoKey = "${RESOLVE_ARTIFACTORY_REPO}"
username = "${RESOLVE_ARTIFACTORY_USER}"
password = "${RESOLVE_ARTIFACTORY_PASSWORD}"
maven = true
}
}
}
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()) {
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 }
}
}