Last active
December 21, 2015 17:06
-
-
Save mearns/af12960192bf14d4ecc5 to your computer and use it in GitHub Desktop.
Basic gradle build file for java projects with commonly used dependencies
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 { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.1' | |
} | |
} | |
plugins { | |
id 'java' | |
id 'application' | |
id 'com.github.johnrengelman.shadow' | |
} | |
version 1.0 | |
//FIXME: Set path to main classname. | |
mainClassName = 'com.brianmeans.MainClass' | |
repositories { | |
jcenter() | |
mavenCentral() | |
} | |
dependencies { | |
//For basic command line parsing and option definitions. | |
compile 'commons-cli:commons-cli:1.3.1' | |
//For working with databases. | |
compile 'org.jdbi:jdbi:2.63.1' | |
//JDBC driver for connecting to databases. | |
compile 'net.sourceforge.jtds:jtds:1.2.2' | |
//Lots of useful stuff here. | |
compile 'com.google.guava:guava:18.0' | |
//@NotNull and @Nullable annotations | |
compile 'com.intellij:annotations:12.0' | |
//Logging | |
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.5' | |
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.5' | |
compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version:'2.5' | |
compile 'org.slf4j:slf4j-api:1.7.13' | |
//Unit testing framework. | |
testCompile 'junit:junit:4.12' | |
} | |
//Attributes to add to Jar and ShadowJar | |
Map<String, String> jarAttributes = [ | |
"Gradle-Version": gradle.gradleVersion, | |
"Host": InetAddress.getLocalHost().getHostName(), | |
"Built-By": System.getProperty("user.name"), | |
"Build-Jdk": System.getProperty("java.version"), | |
"GradleProjectName": project.name, | |
"Main-Class": mainClassName | |
] + (Map<String, String>)[ | |
//Add more jar attributes from ENV VARs, if they exist. | |
"BUILD_ID" : "Build-Id", | |
"BUILD_NUMBER" : "Build-Number", | |
"HG_COMMIT" : "HG-Commit", | |
"HG_BRANCH" : "HG-Branch", | |
"APP_VERSION" : "App-Version", | |
"KICKED_OFF_BY": "Kicked-Off-By" | |
] | |
//Map to env-vars | |
.collectEntries { String envVar, String attrName -> [attrName, System.getenv(envVar) ] } | |
//Skip any that have null values | |
.findAll { attrName, envValue -> envValue } | |
jar { | |
manifest { | |
attributes(jarAttributes) | |
} | |
} | |
//Build a "shadow jar" (aka a "fat jar") | |
shadowJar { | |
classifier "standalone" //Gets added to the file name. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment