Problem
With Gradle the project name is derived from the project's directory name. However, in Jenkins the project's directory name is derived from the Jenkins job name.
There are a few steps in the build lifecycle that use the
project.name
, such as the jar task. If our Jenkins job was "myProject_build" this would result in a jar named myProject_build-1.0.jar
.Solution
With a single project the solution is to add a
settings.gradle
and set the (root) project name there (rootProject.name = "..."
).
With a multi-project build you may wish to override the sub-project name:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include 'mySubProject' | |
findProject(':mySubProject').name = '...' |

In this recipe we will see how easy it is to call the Weblogic tool "wldeploy" from Gradle.
Getting ready
The deployment depends on having a copy of the wlfullclient.jar available to the build scripts. There are plenty of tutorials online on how to create this, so I wont cover that here.
How to do it ...
- Create our build file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript{ | |
configurations { | |
weblogic | |
} | |
dependencies { | |
weblogic files('/path/to/wlfullclient.jar') | |
} | |
} | |
/******************************************************************* | |
LOAD PROJECT CONFIGURATION | |
Usage: this task slurps the configuration that is defined in ./gradle/config/weblogicBuildConfig.groovy | |
into a property called config. | |
********************************************************************/ | |
task loadConfiguration { | |
def env = project.hasProperty('env') ? project.getProperty('env') : 'local' | |
logger.quiet "Loading configuration for environment '$env'" | |
def configFile = file("$rootDir/gradle/config/weblogicBuildConfig.groovy") | |
def parsedConfig = new ConfigSlurper(env).parse(configFile.toURL()) | |
allprojects { | |
ext{ | |
config = parsedConfig | |
} | |
} | |
} | |
/******************************************************************* | |
DEPLOY TO WEBLOGIC | |
Usage: Deploy each file in the ./build/libs directory. | |
Parameters: -Penv | |
********************************************************************/ | |
task deployToWLS { | |
group = 'Deployment' | |
description = 'Deploy artifacts to a weblogic server. Requires -Penv=<env>' | |
} << { | |
ant.taskdef( name: 'wldeploy', | |
classname: 'weblogic.ant.taskdefs.management.WLDeploy', | |
classpath: configurations.weblogic.asPath | |
) | |
new File("$buildDir/libs/").eachFile { file -> | |
// Get the filename minus the extension | |
def filename = file.getName().split("\\.")[0] | |
logger.lifecycle "[INFO] deploying $file to $env weblogic instance" | |
ant.wldeploy(action: 'deploy', | |
source: file, | |
name: filename, | |
adminurl: config.wls.adminurl, | |
user: config.wls.user, | |
password: config.wls.password, | |
upload: config.wls.upload, | |
targets: config.wls.targets, | |
verbose: config.wls.verbose, | |
debug: config.wls.debug | |
) | |
} |
- Create our Weblogic instance configurations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
environments { | |
local { | |
wls { | |
adminurl = 't3://localhost:7001' | |
user = 'weblogic' | |
password = 'welcome1' | |
targets = 'AdminServer' | |
upload = 'true' | |
verbose = 'true' | |
debug = 'false' | |
} | |
} | |
} |
How it works ...
I wont get into the configuration elements of this project. Its covered in great detail here. The important thing to take from this is we are tokenizing our build scripts making them reusable.
The deployToWLS task is where the magic happens. Here we define the ant task using the name, classname and classpath. Next we specify a directory with our deployables; I've used the "build/libs" directory as that's where my war files are packaged to. Next, through the powers of the eachFile closure we get the filename and trim the extension, we then deploy each file in that directory.
I've been using this for a few months now and whilst my usage isn't massive, I do tend to use the command line about once a day.
Here's some of my most used tasks:
setEnv
Here's some of my most used tasks:
setEnv
I wrote an environment configuration script in a previous post that I want to be called when I open ConEmu. The picture above shows how.
Git Bash
My VCS of choice is Git and it comes with Git Bash to allow me to call some of my favourite Git commands. Here's how that's integrated into ConEmu.
setWLSEnv
Finally, I use Weblogic for a lot of my Java EE container needs. To set the system path and classpath Weblogic comes with a setWLSEnv script. In a similar way to calling my own, here I simply call the setWLSEnv script provided by Weblogic.
Subscribe to:
Posts (Atom)