Build.gradle: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 54: Line 54:
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
// This is a comment
// This is a comment
</syntaxhighlight>
=Code=
The build script may include general-purpose Java and Groovy code:
<syntaxhighlight lang='groovy'>
class Experimental {
    private String name;
    Experimental(String name) {
        this.name = name;
    }
    @Override
    public String toString() {
        return name;
    }
}
def experimental = new Experimental("blue");
task test {
    doLast {
        println experimental
    }
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 22:05, 8 October 2020

External

Internal

Overview

build.gradle is the script interface to a Project instance.

Example

apply plugin: 'java'

// name comes from the directory name or it can be changed in settings.gradle
group = "playground.example"
version = "0.1.0"
description = "A Gradle example project"

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    implementation 'org.slf4j:slf4j-api:1.7.12'
    testImplementation 'junit:junit:4.+'
}

configurations {
    testImplementation.exclude group: 'com.example'
}

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 3600, 'seconds'
}

compileJava {
    options.compilerArgs += ['-Xlint']
}

javadoc {
    options.charSet = 'UTF-8'
}

task runMain(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = "io.novaordis.playground.gradle.java.Main"
}

Comments

// This is a comment

Code

The build script may include general-purpose Java and Groovy code:

class Experimental {

    private String name;

    Experimental(String name) {

        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }
}

def experimental = new Experimental("blue");

task test {
    doLast {
        println experimental
    }
}