User Tools

Site Tools


gradle

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gradle [2018/03/05 12:25] skipidargradle [2021/04/14 07:13] (current) skipidar
Line 119: Line 119:
 1 actionable task: 1 executed 1 actionable task: 1 executed
 </code> </code>
 +
 +
 +==== Using environment variabls ====
 +
 +Look out for hte type conversion here.
 +Integer is expected, so you mast cast explicitely
 +<code>
 +Integer.parseInt(System.getenv('INCREMENTAL_VERSION'))
 +</code>
 +
 +<code>
 +// 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'))
 +}
 +</code>
 +
 +
 +
 +
 +=== 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
 +
 +<sxh java>
 +
 +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"
 +}
 +</sxh>
 +
 +Assuming that the SPring boot application is under 
 +
 +<sxh java>
 +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);
 +    }
 +}
 +</sxh>
 +
 +
 +
gradle.1520252722.txt.gz · Last modified: (external edit)