I've create a gradle script in order to deploy a deployable on a container using cargo plugin:
class RemoteContainer {
String name
String container
String hostname
Integer port
String username
String password
String purpose
}
def remoteContainers = [new RemoteContainer(
name: 'wildfly10',
container: 'wildfly10x',
hostname: 'localhost',
port: 9990,
username: 'user',
password: 'passwd',
purpose: 'development'
)
]
remoteContainers.each { config ->
task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
description = "Deploys WAR to remote Web Application Server: '${config.name}'."
containerId = config.container
hostname = config.hostname
port = config.port
username = config.username
password = config.password
dependsOn war
}
task "undeployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoUndeployRemote) {
description = "Deploys WAR to remote Web Application Server: '${config.name}'."
containerId = config.container
hostname = config.hostname
port = config.port
username = config.username
password = config.password
dependsOn = war
}
}
Nevertheless, I've created several tasks in order to create custom war files according to its scope:
task createQAWar(type: War, dependsOn: classes) {
archiveName "webapi-demo-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
...
}
}
task createDevelopmentWar(type: War, dependsOn: classes) {
archiveName "webapi-dev-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
...
}
}
task createTestingWar(type: War, dependsOn: classes) {
archiveName "webapi-test-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
...
}
}
task createProductionWar(type: War, dependsOn: classes) {
archiveName "webapi-prod-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
...
}
}
I'd like to link that deployDev tasks pick the war artifact generated on createDevelopmentWar.
I've tried to set dependsOn property to createDevelopmentWar:
remoteContainers.each { config ->
task "deployDev${config.name.capitalize()}"(type: com.bmuschko.gradle.cargo.tasks.remote.CargoDeployRemote) {
description = "Deploys WAR to remote Web Application Server: '${config.name}'."
containerId = config.container
hostname = config.hostname
port = config.port
username = config.username
password = config.password
dependsOn = createDevelopmentWar <<<<<<<<<<<<<<<<<
}
}
Nevertheless, gradle it's getting me this message:
What went wrong:
A problem occurred evaluating root project 'webapi'.
Cannot cast object 'task ':createDevelopmentWar'' with class 'org.gradle.api.tasks.bundling.War_Decorated' to class 'java.lang.Iterable
'
I've also tried setting dependsOn to war task, nevertheless the message is the same.
EDIT
Once, I've changed the syntax for dependsOn = [createDevelopmentWar], I'm facing up with another trouble:
It's getting me this message:
Execution failed for task ':deployDevWildfly10'.
Deployable D:\projects\living\platform\webapi\build\libs\webapi-dev-89c157a-dirty.war does not exist
It's trying to get the artifact from build\libs\. Nevertheless, the war artifact has been created in destinationDir = file("$buildDir/dist"):
task createDevelopmentWar(type: War, dependsOn: classes) {
archiveName "webapi-dev-${versioning.info.display}.war"
destinationDir = file("$buildDir/dist")
webInf {
...
}
}
How could I set cargo picks the artifact up from previously war type task(createDevelopmentWar) execution information?
dependsOn = createDevelopmentWar results in a call to setDependsOn(createDevelopmentWar) which expects an Iterable that a task is not.
dependsOn createDevelopmentWar would result in a call to dependsOn(createDevelopmentWar) which expects a varargs parameter and thus sould add the task to the dependencies.
If you really want to replace all dependencies with this one dependency, you have to do it like dependsOn = [createDevelopmentWar].
Related
I need to migrate from Transmode gradle docker plugin to Palantir docker gradle plugin.
Old task is as below,
task buildDocker(type: Docker, dependsOn: build) {
group "docker"
push = false
applicationName = awsContainerRepositoryName()
dockerfile = pickDockerfile()
tagVersion = "local"
doFirst {
copy {
from jar
into stageDir
rename { String fileName ->
fileName.replace("${jar.baseName}-${project.version}", "app")
}
}
new File(stageDir, "service_version.txt").text = "${project.version}"
copy {
from "${buildDir}/asciidoc/html5/index.html"
into "${stageDir}/api-documentation/"
}
if (project.hasProperty('customDockerRunStep')) {
runCommand project.customDockerRunStep
}
exec {
commandLine 'bash', 'shared-build/aws/retrieve_aws_ecr_login.sh'
}
}
}
I am trying to add doFirst block as below,
docker {
dependsOn assemble
name awsContainerRepositoryName()
dockerfile file(pickDockerfile())
files bootJar.archivePath
doFirst {
// some code
}
}
But it is giving below error,
* What went wrong:
A problem occurred evaluating root project 'service-abc'.
> No signature of method: build_dgdrt7rh9kp8lojc44jud6em6.docker() is applicable for argument types: (build_dgdrt7rh9kp8lojc44jud6em6$_run_closure7) values: [build_dgdrt7rh9kp8lojc44jud6em6$_run_closure7#8431bf9]
Please help
I use liquibase in my project, and here is one of my config files:
databaseChangeLog:
- changeSet:
id: 123
author: m.rybalkin
changes:
- update:
columns:
- column:
name: code
value: '123'
schemaName: prod
tableName: config_bundle
where: code='321'
Here is my build.gradle of the "liquibase" module:
group 'com.project.test'
version '0.1.0'
buildscript {
dependencies {
classpath "org.liquibase:liquibase-gradle-plugin:${liqubasePluginVersion}"
classpath "gradle.plugin.com.avast.gradle:gradle-docker-compose-plugin:${gradleDockerComposePluginVersion}"
}
}
apply plugin: 'java'
apply plugin: 'org.liquibase.gradle'
apply plugin: 'com.avast.gradle.docker-compose'
dependencies {
liquibaseRuntime "org.liquibase:liquibase-core:${liquibaseCoreVersion}"
liquibaseRuntime "org.postgresql:postgresql:${postgresqlVersion}"
}
liquibase {
activities {
main {
def file = new File("${projectDir}/liquibase.properties")
if (file.exists()) {
def props = new Properties()
InputStream is = new FileInputStream(file)
props.load(is)
is.close()
changeLogFile props['changeLogFile']
outputFile 'liquibase/sql-migration-bundle.sql'
url props['url']
username props['username']
password props['password']
} else {
println "Add ${projectDir}/liquibase.properties if you want use liquibase plugin"
}
}
dockerPostgres {
changeLogFile "${projectDir}/changelog/changelog-master.yml"
url 'jdbc:postgresql://localhost:5555/test'
username 'test'
password 'test'
}
runList = 'main'
}
}
task localUpdate(dependsOn: "composeUp") {
doFirst {
liquibase.setProperty("runList", "dockerPostgres")
}
finalizedBy update
}
task localDropAll(dependsOn: "composeUp") {
doFirst {
liquibase.setProperty("runList", "dockerPostgres")
}
finalizedBy dropAll
}
I have two different names of my schema, a "prod" for production and a "test" for tests.
Is it possible to set a variable in my application.yml or build.gradle for changing the name when I'm testing my app and when I'm deploying it?
P.S. I also have two different profiles of my Spring app - "prod" and "test"
You certainly can add properties at runtime of liquibase (which can be passed in from gradle, directly from commandline, etc).
So you can for example call liquibase on the CLI:
liquibase -Durl= update
Before is a snippet of my build.gradle, it lists a series of tasks which should ideally be run in the following order:
createPropertiesFile
jar
obfuscate
deleteNonObfuscatedJar
deletePropertiesFile
I need createPropertiesFile to run before jar, as users are building the .jar using ./gradlew jar.
The problem I'm seeing at the moment is this error:
> Could not find method doFirst() for arguments [task ':createAuthenticationPropertiesFile']
on task ':jar' of type org.gradle.api.tasks.bundling.Jar.
I've also tried jar.dependsOn(project.tasks.createAuthenticationPropertiesFile) but I've seen that custom.properties is not included in the generated .jar when using jar.dependsOn
build.gradle:
nonObfuscatedJar = 'appNotObfuscated.jar'
task createPropertiesFile << {
def props = project.file('src/main/resources/custom.properties')
props << 'prop1=value1'
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveName = "$nonObfuscatedJar"
from sourceSets.main.output.classesDir
from configurations.compileOnly.asFileTree.files.collect { zipTree(it) }
include '**/*.class'
include '**/custom.properties'
manifest {
attributes 'Main-Class': 'com.bobbyrne01.App'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.txt'
injars "$libsDir/$nonObfuscatedJar"
outjars "$libsDir/app.jar"
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
}
task deleteNonObfuscatedJar (type: Delete) {
delete "$libsDir/$nonObfuscatedJar"
}
task deletePropertiesFile (type: Delete) {
delete project.file('src/main/resources/custom.properties')
}
jar.doFirst(project.tasks.createPropertiesFile)
jar.finalizedBy(project.tasks.obfuscate)
jar.finalizedBy(project.tasks.deleteNonObfuscatedJar)
jar.finalizedBy(project.tasks.deletePropertiesFile)
As a workaround, move the properties file creation to the start of the jar task:
jar {
// Create properties file
def props = project.file('src/main/resources/custom.properties')
props << 'prop1=value1'
// Build jar
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveName = "$nonObfuscatedJar"
from sourceSets.main.output.classesDir
from configurations.compileOnly.asFileTree.files.collect { zipTree(it) }
include '**/*.class'
include '**/custom.properties'
manifest {
attributes 'Main-Class': 'com.bobbyrne01.App'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
I have a gradle project from which I want to generate two artifacts - a java jar, and a tarball of additional files.
So I added the following to my build.gradle
def serviceName = "kafka-schemas"
task packageDistribution(type: Copy) {
from "$buildDir/resources/main"
include "*.avsc"
into "$buildDir/schemas"
}
task archive(type: Tar) {
dependsOn 'packageDistribution'
compression = 'GZIP'
from("$buildDir/schemas") {
include "**/*.avsc"
}
into("${serviceName}")
}
project.tasks.findByName('build') dependsOn archive
project.tasks.findByName('build') dependsOn packageDistribution
However when I run gradle clean build it does not run my tasks.
What am I doing wrong?
Try this:
processResources.dependsOn('packageDistribution')
task packageDistribution(type: Zip) {
archiveFileName = "xxxxx.zip"
destinationDirectory = file("$buildDir/dist")
from "xxxx"
}
I have the following build.gradle file:
plugins {
id 'java-gradle-plugin'
id 'com.gradle.plugin-publish' version '0.10.1'
id 'groovy'
id 'maven-publish'
id "com.jfrog.artifactory" version "4.9.1"
}
group = 'de.gafertp'
version = '2.0.0'
repositories {
mavenCentral()
}
dependencies {
compile 'net.sourceforge.plantuml:plantuml:1.2019.1'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.4.0'
testCompile 'org.junit-pioneer:junit-pioneer:0.3.0'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
}
gradlePlugin {
plugins {
plantUmlPlugin {
id = 'de.gafertp.plantuml'
displayName = 'Gradle PlantUML Plugin'
description = 'A very simple plugin to render PlantUML files. ' +
'Takes a set of diagram files together with desired output files / formats ' +
'and renders them with PlantUML (http://plantuml.com/).'
implementationClass = 'de.gafertp.PlantUmlPlugin'
}
}
}
pluginBundle {
website = 'https://github.com/codecholeric/gradle-plantuml-plugin'
vcsUrl = 'https://github.com/codecholeric/gradle-plantuml-plugin'
tags = ['plantuml']
}
publishing {
publications {
plantUmlPluginJar(MavenPublication) {
from components.java
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
println "username=${artifactory_user}"
println "password=${artifactory_password}"
maven = true
}
defaults {
publications('plantUmlPluginJar')
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
test {
useJUnitPlatform()
}
And this gradle.properties file:
artifactory_user=${security.getCurrentUsername()}
artifactory_password=${security.getEncryptedPassword()!"blahblah"}
artifactory_contextUrl=http://localhost:8081/artifactory
The build fails with the following error:
Execution failed for task ':artifactoryDeploy'.
> java.io.IOException: Failed to deploy file. Status code: 401 Response message: Artifactory returned the following errors:
Unauthorized Status code: 401
If we take a look at the printed username and password, we see this:
username=${security.getCurrentUsername()}
password=${security.getEncryptedPassword()!"blahblah"}
Gradle takes the properties values as literal strings instead of evaluating them. So the issue seems to be that the security object cannot be found, because if I replace the properties in build.gradle file with their values directly, the following error occurs:
A problem occurred evaluating root project 'gradle-plantuml-plugin'.
> Could not get unknown property 'security' for object of type org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper.
What am I doing wrong? The deploy works fine when using plaintext username and password, but I would like to use the auto-generated way of logging in (using an encrypted password).
It seems that gradle.properties should look like this:
username=your_username
password=blahblah
We suppose that blahblah is your encrypted password.