User Tools

Site Tools


gradle

Gradle

Gradle Wrapper

gradlew - is the gradle wrapper, which downloads the correct gradle version. Is makes you independent from the local gradle version.

Tasks

To list all tasks of the project do

gradlew tasks --all
$ gradlew tasks --all



> Task :tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Application tasks
-----------------
bootRun - Runs this project as a Spring Boot application.

Build tasks
-----------
assemble - Assembles the outputs of this project.
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
bootWar - Assembles an executable war archive containing webapp content, and the main classes and their dependencies.
build - Assembles and tests this project.
buildClientDev - Compile client side folder for development
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
war - Generates a war archive with all the compiled classes, the web-app content and the libraries.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'de.webapp.spring.one'.
components - Displays the components produced by root project 'de.webapp.spring.one'. [incubating]
dependencies - Displays all dependencies declared in root project 'de.webapp.spring.one'.
dependencyInsight - Displays the insight into a specific dependency in root project 'de.webapp.spring.one'.
dependencyManagement - Displays the dependency management declared in root project 'de.webapp.spring.one'.
dependentComponents - Displays the dependent components of components in root project 'de.webapp.spring.one'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'de.webapp.spring.one'. [incubating]
projects - Displays the sub-projects of root project 'de.webapp.spring.one'.
properties - Displays the properties of root project 'de.webapp.spring.one'.
tasks - Displays the tasks runnable from root project 'de.webapp.spring.one'.

IDE tasks
---------
cleanEclipse - Cleans all Eclipse files.
cleanEclipseWtp - Cleans Eclipse wtp configuration files.
cleanIdea - Cleans IDEA project files (IML, IPR)
eclipse - Generates all Eclipse files.
eclipseWtp - Generates Eclipse wtp configuration files.
idea - Generates IDEA project files (IML, IPR, IWS)

Node tasks
----------
nodeSetup - Download and install a local node/npm version.
npmInstall - Install node packages from package.json.
npmSetup - Setup a specific version of npm to be used by the build.
yarn - Install node packages using Yarn.
yarnSetup - Setup a specific version of Yarn to be used by the build.

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

Other tasks
-----------
cleanEclipseClasspath
cleanEclipseJdt
cleanEclipseProject
cleanEclipseWtpComponent
cleanEclipseWtpFacet
cleanIdeaModule
cleanIdeaProject
cleanIdeaWorkspace
compileJava - Compiles main Java source.
compileTestJava - Compiles test Java source.
eclipseClasspath - Generates the Eclipse classpath file.
eclipseJdt - Generates the Eclipse JDT settings file.
eclipseProject - Generates the Eclipse project file.
eclipseWtpComponent - Generates the Eclipse WTP component settings file.
eclipseWtpFacet - Generates the Eclipse WTP facet settings file.
ideaModule - Generates IDEA module files (IML)
ideaProject - Generates IDEA project file (IPR)
ideaWorkspace - Generates an IDEA workspace file (IWS)
processResources - Processes main resources.
processTestResources - Processes test resources.
taskTree

Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
Pattern: "npm_<command>": Executes an NPM command.
Pattern: "yarn_<command>": Executes an Yarn command.


BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

Using environment variabls

Look out for hte type conversion here. Integer is expected, so you mast cast explicitely

Integer.parseInt(System.getenv('INCREMENTAL_VERSION'))
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext.majorVersion=1
ext.minorVersion=3
ext.incrementalVersion=1
if (System.getenv('INCREMENTAL_VERSION') != null) {
    ext.incrementalVersion=Integer.parseInt(System.getenv('INCREMENTAL_VERSION'))
}

Fork a Java process from Gradle

Here a snippet about forking the process, e.g. for launching the app under test for load tests, contract tests.

It waits for the Spring boot application to come up. For that it looks at the port 8080 and checks the STDOUT for the string “started”.

Example: https://github.com/skipidar/spring-boot-template


buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springbootVersion")
        classpath "gradle.plugin.com.github.hesch:gradle-execfork-plugin:0.1.15"
    }
}


plugins {
    id "au.com.dius.pact" version "4.2.2"
    id 'com.github.hesch.execfork' version '0.1.15'
}

apply plugin: "org.springframework.boot"

jar {
    baseName = 'account-api'
    version = "$version"
}

dependencies {
    compile(
            "org.springframework.boot:spring-boot-starter-parent:$springbootVersion",
            "org.springframework.boot:spring-boot-starter-web:$springbootVersion",
            "org.springframework.boot:spring-boot-starter-jersey:$springbootVersion",
            "javax.xml.bind:jaxb-api:2.3.1",
            "org.slf4j:slf4j-api:$slf4jVersion"
    )

    testCompile(
            "org.assertj:assertj-core:$assertjVersion",
            "org.springframework.boot:spring-boot-starter-test:$springbootVersion"
    )
}

task startProvider(type: com.github.psxpaul.task.JavaExecFork) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'com.dius.account.Application'
//    args = [ '-d', '/foo/bar/data', '-v', '-l', '3' ]
    jvmArgs = ['-Xmx500m', '-Djava.awt.headless=true']
    workingDir = "$buildDir/server"
    standardOutput = "$buildDir/daemon.log"
    errorOutput = "$buildDir/daemon-error.log"
//    stopAfter = verify
    waitForPort = 8080
    waitForOutput = 'started'
//    environment 'JAVA_HOME', "C:\\Program Files\\AdoptOpenJDK\\jdk-11.0.7.10-hotspot"
}

Assuming that the SPring boot application is under

package com.dius.account;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class).run(args);
    }
}

gradle.txt · Last modified: 2021/04/14 07:13 by skipidar