Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basic gradle configuration of Java project
plugins {
id 'application'
mainClassName = 'com.igoticecream.rebel.helper.Helper'
applicationDefaultJvmArgs = ["-javaagent:/An/Example/Jvm/Args.jar"]
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
jar {
manifest {
'Main-Class': mainClassName,
'Implementation-Version': project.version,
'Class-Path': configurations.runtime.collect { it.getName() }.join(' ')
allprojects {
group 'com.igoticecream'
version '1.0'
description 'Example'
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
archivesBaseName =
repositories {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.7.5'
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'org.hamcrest:hamcrest-library:1.3'
afterEvaluate {
task fatJar(type: Jar, dependsOn: classes, group: 'build', description: 'Assembles a jar archive containing the main classes with dependencies.') {
classifier = 'all'
from(configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/'
with jar
manifest.from jar.manifest
task sourcesJar(type: Jar, dependsOn: classes, group: 'build', description: 'Assembles a jar archive containing the sources.') {
classifier = 'sources'
from sourceSets.main.allSource
task javadocJar(type: Jar, dependsOn: javadoc, group: 'build', description: 'Assembles a jar archive containing the javadoc.') {
classifier = 'javadoc'
from javadoc.destinationDir
artifacts {
archives jar
archives fatJar
archives sourcesJar
archives javadocJar
task clean(type: Delete, group: 'other', description: 'Cleans the root project build directory.') {
delete rootProject.buildDir
delete fileTree(dir: rootDir, include: '.DS_Store')
delete fileTree(dir: rootDir, include: 'Thumbs.db')
task wrapper(type: Wrapper, group: 'other', description: 'Updates the gradle wrapper version.') {
gradleVersion = '3.3'
distributionType = Wrapper.DistributionType.ALL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment