In my current project I’m using IntelliJ, Gradle and WildFly. I’m relatively new to each of these products only having used each of them for a couple of months. But, as the project is still Java EE 7 the learning curve is more with the tools and application server than with the standard.
Now that I’ve had a little cockpit time I’m quite comfortable with WildFly and getting more comfortable with Gradle all the time. I will admit it’s taken me a while but I’m finally starting to get used to the jump from Maven and (my beloved) Ant.
IntelliJ is quite good but I think NetBeans is still my first choice. I’ve done a lot of coding on NetBeans using GlassFish and they are a solid combination. While there are plugins I would very much like to see Gradle become more highly integrated into NetBeans.
So, in the hope of helping someone else get started I’m laying out 3 items in this post.
1. The directory structure for my project (pretty standard but maybe not obvious to new users)
2. My gradle.properties file just for the heck of it
3. Key parts of my build.gradle file
My development environment is Kubuntu Linux 15.04, Java 8, Git 2.1.4, Gradle 2.5, IntelliJ 14 & Wildfly-9.0.0.Final
I do not use a gradle wrapper. Though, I do see where a gradle wrapper would be a benefit. IntelliJ does an amazing job of importing and syncing with Gradle!! A big plus making the wrapper even less important.
(1)
The directory structure for my project is a pretty standard and is probably familiar to those of you that use Maven.
Gradle seems to be comfortable with the Maven standard layout:
myProject build.gradle gradle.properties --src --java --com.whatever --com.whatever.constant --com.whatever.converter --com.whatever.jpa --com.whatever.ejb --com.whatever.rest --com.whatever.security --com.whatever.ui --com.whatever.validator --com.whatever.webapp (Backing Beans for JSF and stuff) --resources touch.txt (just an empty file so git doesn't delete my empty folder) --sql --webapp --folder1 (JSF) --folder2 (More JSF) --WEB-INF beans.xml ejb-jar.xml faces-config.xml jboss-web.xml web.xml --classes --META-INF persistence.xml --facelets faceletsTemplate1.xhtml faceletsTemplate2.xhtml --lib touch.txt --notes (I keep my notes and snippets of code here) --test --java --com.whatever --resources touch.txt (just an empty file so git doesn't delete my empty folder)
(2)
I don't use any of Gradle's advanced features. If my dev machine was a bit slower I probably would. Even without the 'daemon' and 'parallel' features it's pretty darn fast. Just set those two options to 'true' if you want to try them out.
My gradle.properties file:
# For more details on how to configure your build environment visit
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.daemon=false
org.gradle.parallel=false
(3)
My gradle.build file:
// Add some plugins
// I use cargo to deploy to my local install of WildFly
plugins {
id "com.bmuschko.cargo" version "2.0.3"
id "com.bmuschko.cargo-base" version "2.0.3"
}
// Gotta have these two as this is a Java EE Web Archive project
apply plugin: 'java'
apply plugin: 'war'
// I setup all the versions for my libraries I'm going to use
// LibraryVersions
project.ext.wildflyVersion = "9.0.0.Final"
project.ext.primefacesVersion = "5.2"
project.ext.primefacesThemeVersion = "1.0.10"
project.ext.apachePoiVersion = "3.11"
project.ext.romeVersion = "1.0"
project.ext.apacheCommonsFileUploadVersion = "1.3.1"
project.ext.apacheCommonsIoVersion = "2.4"
project.ext.atmosphereVersion = "2.3.0-RC6"
project.ext.itextVersion = "2.1.7"
project.ext.qrgenVersion = "1.4"
project.ext.barcode4jLightVersion = "2.0"
project.ext.fontAwesomeVersion = "4.3.0-1"
project.ext.junitVersion = "4.12"
project.ext.arquillianVersion = "1.1.8.Final"
project.ext.wildflyArquillianContainerRemoteVersion = "1.0.0.Final"
project.ext.shrinkWrapResolverGradleVersion = "2.2.0-beta-1"
// What I want gradle to do by default when I issue the 'gradle' command with no options
defaultTasks 'clean', 'test', 'build', 'deployToTestServer'
// Some info about the project
// Might use as vars later
description = 'Web Project'
version = '1.0'
String appName = 'myProject'
String vendor = 'My Company, Inc.'
// Let Gradle know I'm using JDK 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
// It's good to have several repositories
repositories {
jcenter()
mavenCentral()
maven {
name "Gradle Repository"
url "https://plugins.gradle.org/m2/"
}
maven {
name "JBoss Public Maven Repository Group"
url "https://repository.jboss.org/nexus/content/groups/public-jboss/"
}
maven {
name "Unofficial PrimeFaces Maven Repository"
url "http://primefaces.github.io/repository"
}
maven {
name "Unofficial PrimeFaces Maven Repository"
url "http://unofaces.github.io/repository"
}
maven {
name "PrimeFaces Repository"
url "http://repository.primefaces.org"
}
}
// Setup Project dependencies
// Notice that my org.wildfly dependencies are 'providedCompile' as I use the Full version of
// Wildfly-9.0.0.Final which seems to include everything plus the kitchen sink
// There is lot's of good stuff in wildfly-feature-pack
dependencies {
// Commons
compile findProject(':aui-common')
// Cargo Plugin Dependencies
cargo "org.codehaus.cargo:cargo-ant:${cargoVersion}"
cargo "org.codehaus.cargo:cargo-core-uberjar:${cargoVersion}"
cargo "org.codehaus.cargo:cargo-core-container-wildfly:${cargoVersion}"
cargo 'org.wildfly:wildfly-controller-client:8.2.0.Final'
// WildFly Components
providedCompile "org.wildfly:wildfly-spec-api:${wildflyVersion}"
providedCompile "org.wildfly:wildfly-feature-pack:${wildflyVersion}"
// PrimeFaces Core and Themes
compile "org.primefaces:primefaces:${primefacesVersion}"
compile "org.primefaces.themes:home:${primefacesThemeVersion}"
// PrimeFaces Dependencies -- Apache POI
compile "org.apache.poi:poi:${apachePoiVersion}"
// PrimeFaces Dependencies -- Other
compile "rome:rome:${romeVersion}"
compile "commons-fileupload:commons-fileupload:${apacheCommonsFileUploadVersion}"
compile "commons-io:commons-io:${apacheCommonsIoVersion}"
compile "org.atmosphere:atmosphere-runtime:${atmosphereVersion}"
compile "com.lowagie:itext-rups:${itextVersion}"
compile "net.glxn:qrgen:${qrgenVersion}"
compile "net.sf.barcode4j:barcode4j-light:${barcode4jLightVersion}"
compile "org.webjars:font-awesome:${fontAwesomeVersion}"
// Unit Testing
testCompile "junit:junit:${junitVersion}"
// Unit Testing Arquillian
//testCompile "org.jboss.arquillian.junit:arquillian-junit-container:${arquillianVersion}"
//testCompile "org.jboss.arquillian.protocol:arquillian-protocol-servlet:${arquillianVersion}"
//testCompile "org.wildfly.arquillian:wildfly-arquillian-container-remote:${wildflyArquillianContainerRemoteVersion}"
//testCompile "org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-gradle-depchain:${shrinkWrapResolverGradleVersion}"
}
//#####################################################################################################################
//################################# Package Web App ##################################################################
//#####################################################################################################################
war {
archiveName = project.name + ".war"
manifest {
attributes("Manifest-Version": version,
"Created-By": vendor,
"Specification-Title": appName,
"Specification-Version": version,
"Specification-Vendor": vendor,
"Implementation-Title": appName,
"Implementation-Version": version,
"Implementation-Vendor": vendor
//"Main-Class" : "com.whatever.HelloWorld",
//"Class-Path" : configurations.compile.collect { it.getName() }.join(' ')
)
}
}
//#####################################################################################################################
//################################# Determine Environment #############################################################
//#####################################################################################################################
String myWorkstation = 'actualNameOfDevelopmentMyWorkstation'
def String buildHostname
def String buildUser
task determineEnv << {
println("The name of myWorkstation' host is " + myWorkstation)
buildHostname = InetAddress.getLocalHost().getHostName().toLowerCase().trim()
println('The name of this build host is ' + buildHostname)
buildUser = System.getProperty("user.name").toLowerCase().trim()
println('The name of this build user is ' + buildUser)
}
//#####################################################################################################################
//################################# Deploy WAR to WildFly #############################################################
//#####################################################################################################################
// http://cargo.codehaus.org/Home
cargo {
containerId = 'wildfly8x' // I know I'm using 9 but haven't seen this updated yet by cargo project
port = 9990
remote {
hostname = 'localhost'
username = 'wildfly' // Use your WildFly admin username
password = 'wildfly' // Use your Wildfly admin password
}
}
task deployToTestServer(type: com.bmuschko.gradle.cargo.tasks.remote.CargoRedeployRemote, dependsOn: ['determineEnv', 'war']) {
println('deployToTestServer')
containerId = 'wildfly8x' // I know I'm using 9 but haven't seen this updated yet by cargo project
port = 9990
hostname = 'localhost'
username = 'wildfly' // Use your WildFly admin username
password = 'wildfly' // Use your WildFly admin password
}
deployToTestServer.onlyIf { buildHostname.equals(myWorkstation) } //I don't want it to deploy when I'm doing development on a different workstation
Thank you so much.
LikeLike