Gradle "application" plugin changing entrypoint script names - gradle

I am using the Gradle Application plugin to package an app so it can be run in a Docker container. Locally this all works fine and the only non-default Gradle build statements I use are:
apply plugin: 'application'
// Rest of build file declaring dependencies, etc.
mainClassName = 'com.example.MyApp'
distributions {
main {
baseName = 'my-app'
}
}
This results in a launch script in <app_base>/bin/my-app.sh.
But when I build the app on Jenkins the launch script is bin/CI_my-app_develop i.e. it adds CI_ and the current branch as a suffix.
How can I disable this behaviour?

You can configure a default CreateStartScripts task as follows:
createStartScripts {
applicationName = 'my-app'
}
No need to create a custom task for that.

Related

How can I share build code script for all my gradle projects (not just subprojects)

I want to have this code snippet
test {
testLogging.showStandardStreams = true
}
Shared for all my gradle projects. Is that possible? Preferrably something I add to ~/.gradle/common.gradle or similar.
Probably the best way to inject build logic into existing build scripts without touching them is using init scripts. So you can create a script like testlogging.gradle that looks like this:
allprojects {
tasks.withType(Test) {
testLogging.showStandardStreams = true
}
}
As you can see I use tasks.withType(Test) instead of test here to reference the test task by type. That has some benefits:
this script works also for builds with no task with name test. This could likely happen (e.g. in multiproject builds)
this script would also apply for any other tasks in your build that are of type Test. Some projects use integTest etc.
To auto apply this script on your machine, you can put it in the folder ~/.gradle/init.d. Gradle considers every .gradle file in there as init script and applies them to each build.
To learn more details about init scripts check the according chapter in the gradle userguide.

How to use Gretty integrationTestTask with a war file?

Is it possible to use gretty integrationTestTask with a project that uses a war folder?
It seems from the documentation appBeforeIntegrationTest does not have access to the war. Is there another way to run test cases so that it uses the war folder?
Ideally, I want jettyStart -> test -> jettyStop to run. Although when I run it straight jettyStart hangs indefinitely, until jettyStop is run. Is there a way to run jettyStart in Gradle in the background or something?
Regardless what file structure your application has, the integrationTestTask is supposed to be configured with the name of an exsiting gradle task to execute when gradle integrationTest is run:
gretty {
// ...
integrationTestTask = 'integrationTest' // name of existing gradle task
// ...
}
What you want to archive is this:
gretty {
integrationTestTask = 'test'
}
Gretty's workflow when calling integrationTest is as follows:

Wrong order of task execution in gradle 3.3

I want to define methods inside my script file, and use them to define build tasks for each project individual (custom library).
ext.buildDockerImage = { imageName ->
def distDir = "${getProject().getBuildDir()}/docker"
copy {
from "${project.getProjectDir()}/src/docker/"
into distDir
}
println 'Build docker image'
}
In my project build.gradle I have created a task:
apply plugin: "war"
apply plugin: "jacoco"
dependency {
// all dependencies
}
task buildDocker() {
apply from: "${project.getRootDir()}/docker/scripts.gradle"
buildDockerImage("admin")
}
The problem is that whenever I am running gradle build, this tasks executes also:
$ gradle build -xtest
Build docker image
# rest of build
As you can see , all I want is to create a custom library that will hold methods, used to create tasks for each project. But currently I cannot import those methods without breaking the build. Method buildDockerImage will work only after war file is added to build directory, so this task must be executed on demand only, I don't want to be included in the process all the time.
My questions:
how make my task to only run when I execute task manually
why, when I execute my build, script executes as first?
Your task buildDocker() defines everything in configuration phase. So when you run your gradle build this will always run.
task buildDocker() {
apply from: "${project.getRootDir()}/docker/scripts.gradle"
buildDockerImage("admin")
}
If you want to run this task as a standalone task, define your stuff in execution phase of the task. something like below
task buildDocker() {
apply from: "${project.getRootDir()}/docker/scripts.gradle"
doLast{
buildDockerImage("admin")
}
}
Read This article
This might help

Nativescript custom gradle task

How to run a custom gradle task in a nativescript android project?
Use case:
I want to upload the apk to google app store using the plugin bellow:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
}
}
apply plugin: 'com.github.triplet.play'
play {
serviceAccountEmail = 'bla#user.iam.gserviceaccount.com'
pk12File = file('../../key.p12')
track = 'alpha'
}
The plugin creates publishApkRelease task
How to run that task alone?
Add the snippet in the gradle script located in your platforms/android/build.gradle and then use the gradle wrapper to invoke the task like so ./gradlew publishApkRelease for bash or gradlew publishApkRelease in the Windows CMD.
Note that if you delete the platforms/android dir, or modify it by removing/re-adding platform through the tns CLI the changes in the gradle script will be wiped. Make a local copy of the build script or write a hook that will modify the gradle file if you don't want to lose your changes.

Gradle: How do I run my LIquibase changesets as part of my normal build process?

I'm using Gradle 2.7 with the Gradle Liquibase plugin v 1.1.1. How do I run my changeSets as part of doing my normal build using
gradle build
? I currently have this in my build.gradle file ...
liquibase {
activities {
main {
File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile 'src/main/resources/db.changelog-1.0.xmlll'
url '${url}'
username '${username}'
password '${password}'
}
runList = main
}
}
However when I run the above command ("gradle build"), the above is not run. I know its not run because the username/password are incorrect and I have no change log file ending in ".xmlll". WHat else do I need to add to assure that hte plugin always attempts to execute the changeset?
You need to define a task dependency from build to update.
build.dependsOn update
To get task to run before your tests (assuming you didn't define a new one), you can do
test.dependsOn update
Ref:
Gradle task docs
You can define this in your gradle build file
apply plugin: 'liquibase'
dependencies {
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.0'
}
liquibase {
activities {
main {
changeLogFile 'changelog.xml'
url 'jdbc:h2:db/liquibase_workshop;FILE_LOCK=NO'
username 'sa'
password ''
}
}
And then run this command
gradle update

Resources