Buildfile style

hi, newbie here. my build file is getting sorta ugly (please see below).

is there any kind of style guide that would help me order stuff?


class MyStuff {
//public static final String main="controller.CommandLine";
public static final String main="gui.Main";
buildscript {
  repositories {
  dependencies {
    classpath 'org.hidetake:gradle-ssh-plugin:1.1.2'
apply plugin: 'org.hidetake.ssh'
task wrapper(type: Wrapper) { gradleVersion='2.3' }
repositories { mavenCentral() }
apply plugin: 'java'
targetCompatibility = "1.8"  
sourceCompatibility = "1.8" = ["src"] = ["tst"]
sourceSets.main.resources.srcDirs = ["resources"]

dependencies {
    compile fileTree(dir: 'lib', includes: ['*.jar'])
    //compile group: 'junit',name:'junit',version: '4.12'
    testCompile group: 'junit',name:'junit',version: '4.12'

remotes {
    web1 {
    host = ''
    user = 'rtayek'
task deliver << { {
    session(remotes.web1) {
    execute 'pwd'
    put from: 'build/libs/go2-0.2.jar', into: 'html/go/go2.jar'
version = '0.2' 
jar {
    manifest {
        attributes 'Main-Class': MyStuff.main
apply plugin: 'distribution'
apply plugin: 'application'
mainClassName = MyStuff.main // for application plugin
//apply plugin: 'checkstyle'
//apply plugin 'project-report'

There’s no real “style guide” per-se for writing build scripts, but here are some tips:

  • Apply all your plugins at the top of your build script.
  • Group related configuration into blocks if possible.
// instead of this = ["src"] = ["tst"]
sourceSets.main.resources.srcDirs = ["resources"]

// do this
sourceSets {
    main {
        java.srcDirs = ['src']
        resources.srcDirs = ['resources']
    test {
        java.srcDirs = ['tst']
  • Group property assignments in one place (source/target compatibility, version, mainClassName, etc).
  • Put buildscript { } block at the top of the build script (as you have it already).
  • Declarative elements like repositories, dependencies, etc should come before imperative elements (ad-hoc tasks).

These are not hard and fast rules, just things I try to keep in mind when writing build scripts. In general, it doesn’t matter so much what conventions you use, so long as you do so consistently across your build scripts.

good. my build file looks much cleaner now (please see below).

i tried to put the maven central into the build script closure, but it did not like that. is there some trick involved?

also, i am not getting any messaged when someone replies to my posts even though i am watching this thread.


I wouldn’t use an inline class just to declare constants. You should be
able to declare constants like that without the entire class wrapper. Be
sure to put those in a consistent place, probably after your “apply” lines,
at least.

I wouldn’t use an inline class just to declare constants. You should be
able to declare constants like that without the entire class wrapper …

true. i am using an inline class just so i don’t accidentally step on something.


btw, i did get an email due to davidmichaelkarr’s post.


No, just make sure mavenCentral() is in the repositories { } block.

The forum software might not send an email if it thinks you’re ‘active’ on the page. There’s a user setting to turn that off and have it always send an email.

i thought i tried that. will try again.


i seem to me getting the emails now.

you are correct, i was active when i did not get those emails.