Skip to content

Instantly share code, notes, and snippets.

@igoticecream
Created February 21, 2017 20:47
Show Gist options
  • Save igoticecream/0a239a0aac03c25b52fce01b5670b529 to your computer and use it in GitHub Desktop.
Save igoticecream/0a239a0aac03c25b52fce01b5670b529 to your computer and use it in GitHub Desktop.
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 {
attributes(
'Main-Class': mainClassName,
'Implementation-Title': project.name,
'Implementation-Vendor': project.group,
'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 = project.name
repositories {
jcenter()
}
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/rxjava.properties'
}
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