Gradle zip task with lazy include property includes itself - gradle

Hi I got this zip task which works great:
def dir = new File("${projectDir.parentFile}/test/")
task testZip(type: Zip) {
from dir
destinationDirectory = dir
include 'toast/**'
archiveFileName = 'test.zip'
}
but then when I make the include property lazy (because I need to in my real case)
def dir = new File("${projectDir.parentFile}/test/")
task testZip(type: Zip) {
from dir
destinationDirectory = dir
include {
'toast/**'
}
archiveFileName = 'test.zip'
}
then it creates a zip that includes everything in the folder, (so the generated archive too). In this test case the inner zip is just corrupted (doesn't run infinitely) but in the real world case it does make an infinite zip. (Not sure why, maybe my best case has too few or small files). Either way the test case shows the problem, the generated zip contains a zip even though it should only contain the toast directory and all of its content.
How do I fix this? I need a lazy include because the directory I want to include is computed by other tasks. I get the exact same problem with Tar except it refuses to create the archive since it includes itself.
Using exclude '*.zip' is a dumb workaround which makes the archive include other folders I don't want. I only want to include a specific folder, lazyly.
Here's what the monster looks like in the real world case. I basically need to retrieve the version of the project from Java to then use that version to name the folders I'm packaging. (Making a libGDX game and packaging it with a jre using packr). The problematic tasks are 'makeArchive_' + platform.
String jumpaiVersion;
task fetchVersion(type: JavaExec) {
outputs.upToDateWhen { jumpaiVersion != null }
main = 'net.jumpai.Version'
classpath = sourceSets.main.runtimeClasspath
standardOutput new ByteArrayOutputStream()
doLast {
jumpaiVersion = standardOutput.toString().replaceAll("\\s+", "")
}
}
def names = [
'win64' : "Jumpai-%%VERSION%%-Windows-64Bit",
'win32' : "Jumpai-%%VERSION%%-Windows-32Bit",
'linux64' : "Jumpai-%%VERSION%%-Linux-64Bit",
'linux32' : "Jumpai-%%VERSION%%-Linux-32Bit",
'mac' : "Jumpai-%%VERSION%%-Mac.app"
]
def platforms = names.keySet() as String[]
def jdks = [
'win64' : 'https://cdn.azul.com/zulu/bin/zulu9.0.7.1-jdk9.0.7-win_x64.zip',
'win32' : 'https://cdn.azul.com/zulu/bin/zulu9.0.7.1-jdk9.0.7-win_i686.zip',
'linux64' : 'https://cdn.azul.com/zulu/bin/zulu9.0.7.1-jdk9.0.7-linux_x64.tar.gz',
'linux32' : 'https://cdn.azul.com/zulu/bin/zulu9.0.7.1-jdk9.0.7-linux_i686.tar.gz',
'mac' : 'https://cdn.azul.com/zulu/bin/zulu9.0.7.1-jdk9.0.7-macosx_x64.zip'
]
def formats = [
'win64' : 'ZIP',
'win32' : 'ZIP',
'linux64' : 'TAR_GZ',
'linux32' : 'TAR_GZ',
'mac' : 'ZIP'
]
File jdksDir = new File(project.buildscript.sourceFile.parentFile.parentFile, 'out/jdks')
File gameJar = new File("${projectDir.parentFile}/desktop/build/libs/Jumpai.jar")
File gameData = new File("${projectDir.parentFile}/desktop/build/libs/Jumpai.data")
File packrDir = new File("${projectDir.parentFile}/out/packr/")
File minimalTmpDir = new File("${projectDir.parentFile}/desktop/build/libs/minimal-tmp")
task minimizeGameJar {
dependsOn ':desktop:dist'
doFirst {
minimalTmpDir.mkdirs()
copy {
from zipTree(gameJar)
into minimalTmpDir
}
for(file in minimalTmpDir.listFiles())
if(file.getName().contains("humble"))
file.delete()
}
}
task makeMinimal(type: Zip) {
dependsOn minimizeGameJar
dependsOn fetchVersion
from minimalTmpDir
include '**'
archiveFileName = provider {
"Jumpai-${->jumpaiVersion}-Minimal.jar"
}
destinationDir packrDir
doLast {
minimalTmpDir.deleteDir()
}
}
task copyGameJar(type: Copy) {
outputs.upToDateWhen { gameData.exists() }
dependsOn ':desktop:dist'
from gameJar.getAbsolutePath()
into gameData.getParentFile()
rename("Jumpai.jar", "Jumpai.data")
}
task setWindowsIcons(type: Exec) {
dependsOn fetchVersion
workingDir '.'
commandLine 'cmd', '/c', 'set_windows_icons.bat', "${->jumpaiVersion}"
}
for(platform in platforms) {
task("getJdk_" + platform) {
String url = jdks[platform]
File jdkDir = new File(jdksDir, platform + "-jdk")
File jdkFile = new File(jdkDir, url.split("/").last())
outputs.upToDateWhen { jdkFile.exists() }
doFirst {
if(!jdkDir.exists())
jdkDir.mkdirs()
if(jdkFile.exists())
{
println jdkFile.getName() + " is already present"
return
}
else
{
println "Downloading " + jdkFile.getName()
new URL(url).withInputStream {
i -> jdkFile.withOutputStream { it << i }
}
}
for(file in jdkDir.listFiles()) {
if(file.equals(jdkFile))
continue
if(file.isFile()) {
if (!file.delete())
println "ERROR: could not delete " + file.getAbsoluteFile()
} else if(!file.deleteDir())
println "ERROR: could not delete content of " + file.getAbsoluteFile()
}
if(url.endsWith(".tar.gz"))// don't mix up archive type of what we downloaded vs archive type of what we compress (in formats)
{
copy {
from tarTree(resources.gzip(jdkFile))
into jdkDir
}
}
else if(url.endsWith(".zip"))
{
copy {
from zipTree(jdkFile)
into jdkDir
}
}
}
}
File packrInDir = new File(packrDir, platform)
String platformRawName = names[platform]
task("packr_" + platform, type: JavaExec) {
outputs.upToDateWhen { new File(packrDir, platformRawName.replace("%%VERSION%%", jumpaiVersion)).exists() }
dependsOn fetchVersion
dependsOn copyGameJar
dependsOn 'getJdk_' + platform
main = 'com.badlogicgames.packr.Packr'
classpath = sourceSets.main.runtimeClasspath
args 'tools/res/packr_config/' + platform + '.json'
workingDir = project.buildscript.sourceFile.parentFile.parentFile
doLast {
File packrOutDir = new File(packrDir, platformRawName.replace("%%VERSION%%", jumpaiVersion));
packrOutDir.deleteDir()
if(packrOutDir.exists())
{
println "ERROR Could not delete packr output " + packrOutDir.getAbsolutePath()
return
}
if(!packrInDir.renameTo(packrOutDir))
println "ERROR Could not rename packr output dir for " + packrInDir.getName()
}
}
if(formats[platform] == 'ZIP')
{
task('makeArchive_' + platform, type: Zip) {
if(platform.contains("win"))
dependsOn setWindowsIcons
dependsOn fetchVersion
dependsOn 'packr_' + platform
from packrDir
destinationDirectory = packrDir
include {
platformRawName.replace("%%VERSION%%", jumpaiVersion) + "/"
}
archiveFileName = provider {
platformRawName.replace("%%VERSION%%", jumpaiVersion) + ".zip"
}
}
}
else if(formats[platform] == 'TAR_GZ')
{
task('makeArchive_' + platform, type: Tar) {
dependsOn 'packr_' + platform
from packrDir
destinationDirectory = packrDir
include {
platformRawName.replace("%%VERSION%%", jumpaiVersion) + '/**'
}
archiveFileName = provider {
platformRawName.replace("%%VERSION%%", jumpaiVersion) + ".tar.gz"
}
extension 'tar'
compression = Compression.GZIP
}
}
else
println 'Unsupported format for ' + platform
}
task deploy {
dependsOn makeMinimal
for(platform in platforms)
dependsOn 'makeArchive_' + platform
}

How do I fix this? I need a lazy include because the directory I want to include is computed by other tasks. I get the exact same problem with Tar except it refuses to create the archive since it includes itself.
You can get what you want by using the doFirst method and modifiying the tasks properties with the passed action.
task('makeArchive_' + platform, type: Zip) {
if(platform.contains("win"))
dependsOn setWindowsIcons
dependsOn fetchVersion
dependsOn 'packr_' + platform
from packrDir
destinationDirectory = packrDir
archiveFileName = provider {
platformRawName.replace("%%VERSION%%", jumpaiVersion) + ".zip"
}
doFirst {
def includeDir = platformRawName.replace("%%VERSION%%", jumpaiVersion)
// Include only files and directories from 'includeDir'
include {
it.relativePath.segments[ 0 ].equalsIgnoreCase(includeDir)
}
}
}
Please have also a look at this answer to a similar question. My solution is just a workaround. If you know your version at configuration phase you can achieve what you want more easily. Writing your own custom tasks or plugins can also help to clean up your build script.

Related

Fill array/args programmatically in Groovy/Gradle

I am trying to fix the args-argument for the executing programm for this Gradle task:
task generateResources(type: JavaExec) {
group = 'build'
description = 'Generate resource bundle from excel file'
mainClass.set('com.project.MainClass')
ext {
destDir = ''
sourceFile = ''
isDir = false
setInputDir = { input ->
xlxsTree = fileTree(input).matching { include '*.xls' }
xlxsTree.files.each {
args[1] = "$it" //how can I add all matching files???
}
}
setOutput = { output ->
outputs.dir(output)
destDir = output
args[0] = destDir
}
}
setInputDir("${project.projectDir}\\src\\main\\resources\\properties")
setOutput("${project.buildDir}\\resources\\generatedProperties")
logging.captureStandardOutput LogLevel.INFO
onlyIf {
!sourceFile.empty
}
classpath = project.configurations.resbundles
doFirst {
args args
jvmArgs '-Dfile.encoding=ISO-8859-15'
}
The args-argument in doLast{} should contain all file paths ending with .xls, e. g. ["C:\...\src\main\resources\properties\destdir", "C:\...\resources\generatedProperties\file1", "C:\...\resources\generatedProperties\file2"].
My approach is not working at all, I just tried to make it compile for at least one input file.

Child process exited with code 1 LibGDX jPackageImage task

I am using jpackage to convert my libgdx game to an executable file. I am following this tutorial to do so. The jpackageImage task works perfectly fine but when the exe is created and I run it, it doesn't run but rather gives me an error: Child process exited with code 1 I am unaware what is causing this.
I am on windows 11 and im using JDK 18.0.1.1.
The JDK is set to JAVA_HOME which is set to the correct PATH.
I am using Badass-Runtime plugin as well which is defined in the first line of my build.gradle file.
Here is my build.gradle file for desktop:
plugins { id 'org.beryx.runtime' version '1.8.4' }
sourceCompatibility = 1.7
sourceSets.main.java.srcDirs = ["src/"]
sourceSets.main.resources.srcDirs = ["../core/assets"]
mainClassName = "com.mygdx.game.desktop.DesktopLauncher"
def osName = System.getProperty('os.name').toLowerCase(Locale.ROOT)
project.ext.assetsDir = new File("../core/assets")
task runGame(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
destinationDirectory = file("$buildDir/lib")
}
jpackageImage.dependsOn dist
dist.dependsOn classes
eclipse.project.name = appName + "-desktop"
runtime {
options = ['--strip-debug',
'--compress', '2',
'--no-header-files',
'--no-man-pages',
'--strip-native-commands',
'--vm', 'server']
modules = ['java.base',
'java.desktop',
'jdk.unsupported']
distDir = file(buildDir)
jpackage {
jpackageHome = 'C:\\Users\\pc\\.jdks\\openjdk-18.0.1.1'
mainJar = dist.archiveFileName.get()
if (osName.contains('windows')) {
imageOptions = ["--icon", file("../icons/icon.ico")]
} else if (osName.contains('linux')) {
imageOptions = ["--icon", file("../icons/icon.png")]
} else if (osName.contains('mac')) {
imageOptions = ["--icon", file("../icons/icon.icns")]
}
}
}
Is it this bug? bugs.openjdk.org/browse/JDK-8284067 which triggers because your code exits with 1. Try doing with System.exit(0); , there is a workaround listed as well.

Skipping task as it has no source files and no previous output files

This is my build.gradle which has three tasks (one for downloading the zip, one for unzipping it and other for executing the sh file). These tasks are dependent on each other. I am using Gradle 6. As these are dependent tasks I have used following command:
gradlew C
I get the error:
Skipping task 'B' as it has no source files and no previous output files.
build.gradle:
task A {
description = 'Rolls out new changes'
doLast {
def url = "https://${serverName}/xxx/try.zip"
def copiedZip = 'build/newdeploy/try.zip'
logger.lifecycle("Downloading $url...")
file('build/newdeploy').mkdirs()
ant.get(src: url, dest: copiedZip, verbose: true)
}
}
task B (type: Copy, dependsOn: 'A') {
doLast {
def zipFile = file('build/newdeploy/try.zip')
def outputDir = file("build/newdeploy")
from zipTree(zipFile)
into outputDir
}
}
task C (type: Exec, dependsOn: 'B') {
doLast {
workingDir 'build/newdeploy/try/bin'
executable 'sh'
args arguments, url
ext.output = { return standardOutput.toString() }
}
}
I tried following and it worked. Rather than adding a separate task to copy, added the copy function in the task A itself
task A {
description = 'Rolls out new changes'
doLast {
def url = "https://${serverName}/xxx/try.zip"
def copiedZip = 'build/newdeploy/try.zip'
logger.lifecycle("Downloading $url...")
file('build/newdeploy').mkdirs()
ant.get(src: url, dest: copiedZip, verbose: true)
def outputDir = file("build/newdeploy")
copy {
from zipTree(zipFile)
into outputDir
}
}
}
task C (type: Exec, dependsOn: 'A') {
doLast {
workingDir 'build/newdeploy/try/bin'
executable 'sh'
args arguments, url
ext.output = { return standardOutput.toString() }
}
}

Execute a task only if a particular task is run

I want the task setupDB to execute if and only if the task fatJar or slimJar is run.
But after adding gradle.taskGraph.whenReady, commandLine './scripts/configureSQLiteDB.sh' is never running for any task.
Here is my code for the setupDB task:
//download bigg.sqlite if not present
task setupDB {
gradle.taskGraph.whenReady { graph ->
if (!project.file("resources/edu/ucsd/sbrg/bigg/bigg.sqlite").exists()
&& (graph.hasTask(slimJar)|| graph.hasTask(fatJar))) {
doFirst {
exec {
println "Setup DB"
commandLine './scripts/configureSQLiteDB.sh'
}
}
}
}
}
You can also view the build.gradle file:
apply plugin: "java"
defaultTasks "clean", "fatJar"
// Java versions for compilation and output
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
archivesBaseName = "ModelPolisher"
version = "1.7"
sourceSets {
main.java.srcDirs = ["src"]
main.resources.srcDirs = ["resources"]
main.resources.excludes = ["**/bigg.zip"]
test.java.srcDirs = ["test"]
}
repositories {
mavenCentral()
maven { url "http://www.ebi.ac.uk/~maven/m2repo" }
maven { url "http://jsbml.sourceforge.net/m2repo/" }
// local dependencies
flatDir {
dirs "lib/de/zbit/SysBio/1390"
}
}
dependencies {
compile "org.sbml.jsbml:jsbml:1.4"
compile "de.zbit:SysBio:1390"
compile "org.xerial:sqlite-jdbc:3.21.0"
compile "org.postgresql:postgresql:42.2.2"
compile "org.biojava:biojava-ontology:5.0.0"
compile "com.diffplug.matsim:matfilerw:3.0.1"
compile "com.fasterxml.jackson.core:jackson-core:2.9.9"
compile "com.fasterxml.jackson.core:jackson-databind:2.9.9"
testCompile "org.junit.jupiter:junit-jupiter-engine:5.1.0"
}
// config for all jar tasks
tasks.withType(Jar) {
dependsOn test
destinationDir = file("$rootDir/target")
manifest {
attributes(
"Version": version,
"Implementation-Title": "ModelPolisher",
"Implementation-Version": version,
"Specification-Vendor": "University of California, San Diego",
"Specification-Title": "ModelPolisher",
"Implementation-Vendor-Id": "edu.ucsd.sbrg",
"Implementation-Vendor": "University of California, San Diego",
"Main-Class": "edu.ucsd.sbrg.bigg.ModelPolisher"
)
}
}
// with dependencies
task fatJar(type: Jar) {
baseName = project.name + "-fat"
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jar
}
//with dependencies, without bigg.sqlite
task lightJar(type: Jar) {
exclude("**/bigg.sqlite")
baseName = project.name + "-noDB"
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
with jar
}
// without dependencies and bigg.sqlite
task bareJar(type: Jar) {
exclude("**/bigg.sqlite")
baseName = project.name + "-slim-noDB"
with jar
}
// without dependencies, bigg.sqlite included
// not included in release
task slimJar(type: Jar) {
baseName = project.name + "-slim"
with jar
}
// zip lib folder for release
task zipLibs(type: Zip) {
from "lib"
into "lib"
include "**/**"
archiveName = "lib.zip"
destinationDir = file("target/")
}
// zip script files for release
task zipScripts(type: Zip) {
from "scripts"
into "scripts"
include "**/**"
archiveName = "scripts.zip"
destinationDir = file("target/")
}
// create all three jars for release
task release() {
dependsOn fatJar
dependsOn bareJar
dependsOn lightJar
dependsOn tasks["zipLibs"]
dependsOn tasks["zipScripts"]
// necessary, as order is not defined by dependsOn
bareJar.mustRunAfter classes
// slimJar.mustRunAfter bareJar
lightJar.mustRunAfter slimJar
fatJar.mustRunAfter lightJar
}
// clean up target directory
clean.doFirst {
file(".gradle").deleteDir()
file("target").deleteDir()
}
//download bigg.sqlite if not present
task setupDB {
gradle.taskGraph.whenReady { graph ->
if (!project.file("resources/edu/ucsd/sbrg/bigg/bigg.sqlite").exists()
&& (graph.hasTask(slimJar)|| graph.hasTask(fatJar))) {
doFirst {
exec {
println "Setup DB"
commandLine './scripts/configureSQLiteDB.sh'
}
}
}
}
}
// bump jar version in travis.yml
if (project.file(".travis.yml").exists()) {
task bumpVersionTravis() {
replaceVersion(".travis.yml")
}
processResources.dependsOn bumpVersionTravis
}
// bump jar version in ModelPolisher.sh
if (project.file("./scripts/ModelPolisher.sh").exists()) {
task bumpVersionMP() {
replaceVersion("./scripts/ModelPolisher.sh")
}
processResources.dependsOn bumpVersionMP
}
def replaceVersion(path) {
ArrayList<String> content = new ArrayList<>()
File travisFile = new File(path)
String MPVersion = /ModelPolisher.*\d{1,2}(.\d{1,2}){1,2}.jar/
travisFile.eachLine {
line ->
content.add(line.replaceAll(MPVersion, "ModelPolisher-fat-" +
"${version}.jar"))
}
BufferedWriter writer = new BufferedWriter(new FileWriter(travisFile))
content.each {
line -> writer.writeLine(line)
}
writer.close()
}
You seem to have the wrong idea about gradle configuration. You shouldn't be changing task behavior based on inputs. You should be configuring dependencies between tasks and also configuring task inputs/outputs to control the "up-to-date" behaviour.
Eg:
task slimJar(type:Jar) {
dependsOn 'setupDB'
...
}
task fatJar(type:Jar) {
dependsOn 'setupDB'
...
}
task setupDB {
outputs.upToDateWhen { file("resources/edu/ucsd/sbrg/bigg/bigg.sqlite").exists() }
doFirst {
println "Setup DB"
exec {
commandLine './scripts/configureSQLiteDB.sh'
}
}
}
The following is also bad practice
if (project.file(".travis.yml").exists()) {
task bumpVersionTravis() {
replaceVersion(".travis.yml")
}
processResources.dependsOn bumpVersionTravis
}
The available tasks should NOT change based on files in your file system. They should always be there, regardless of your file system. You should instead set the "enabled" flag (or use task outputs) to control if the task executes or is skipped
Eg:
task bumpVersionTravis {
enabled = project.file(".travis.yml").exists()
doLast {
replaceVersion(".travis.yml")
}
}
processResources.dependsOn bumpVersionTravis

Defining custom ‘build’ task is deprecated when using standard lifecycle plugin has been deprecated and is scheduled to be removed in Gradle 3.0

I am facing an issue in my build.gradle script My script is bascially generatiing the POM file and then copy the artifact to other location as well under build/lib with different name.The issue which I am facing How to call the below build task beacuse it is generating the error.I am using gradle 2.3
Error:"Defining custom ‘build’ task is deprecated when using standard lifecycle plugin has been deprecated and is scheduled to be removed in Gradle 3.0"
My task build will build the artifact and then generate the POM and move the artifact to different location but I am getting below error.
My full script is
apply plugin: 'cpp'
apply plugin: 'java'
//-- set the group for publishing
group = 'com.tr.anal'
/**
* Initializing GAVC settings
*/
def buildProperties = new Properties()
file("version.properties").withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.analBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.analBuildVersion
println "${version}"
//name is set in the settings.gradle file
group = "com.t.anal"
version = buildProperties.analBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"
repositories {
maven {
url "http://cm.thon.com:900000/artifactory/libs-snapshot-local"
}
maven {
url "http://cm.thon.com:9000000/artifactory/libs-release"
}
}
dependencies {
compile ([
"com.tr.anal:analytics-engine-common:4.+"
])
}
model {
repositories {
libs(PrebuiltLibraries) {
jdk {
headers.srcDirs "${System.properties['java.home']}/../include",
"${System.properties['java.home']}/../include/win32",
"${System.properties['java.home']}/../include/darwin",
"${System.properties['java.home']}/../include/linux"
}
}
}
}
model {
platforms {
x64 { architecture "x86_64" }
x86 { architecture "x86" }
}
}
model {
components {
main(NativeLibrarySpec) {
sources {
cpp {
source {
lib library: 'main', linkage: 'static'
lib library: 'jdk', linkage: 'api'
srcDir "src/main/c++/native"
include "**/JniSupport.cpp"
include "**/DiseaseStagingJni.cpp"
}
}
}
}
}
}
def nativeHeadersDir = file("$buildDir/nativeHeaders")
//def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(";")
binaries.all {
// Define toolchain-specific compiler and linker options
if (toolChain in Gcc) {
cppCompiler.args "-I${nativeHeadersDir}"
cppCompiler.args "-g"
linker.args '-Xlinker', '-shared -LNativeJNI/src/main/resources/DSresources/DSLib -lds64 -Wl'
}
}
//def nativeHeadersDir = file("$buildDir/nativeHeaders")
task nativeHeaders {
// def nativeHeadersDir = file("$buildDir/nativeHeaders")
def outputFile = file("$nativeHeadersDir/DiseaseStagingJniWrapper.h")
def classes = [
'com.truvenhealth.analyticsengine.common.diseasestaging.DiseaseStagingJniWrapper'
]
inputs.files sourceSets.main.output
inputs.property('classes', classes)
outputs.file outputFile
doLast {
outputFile.parentFile.mkdirs()
def compilePath = configurations.compile.resolve().collect {it.absolutePath}.join(":")
println "Using Compile Path: ${compilePath}"
exec {
executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
args '-o', outputFile
args '-classpath', compilePath
args classes
}
}
}
tasks.withType(CppCompile) { task ->
task.dependsOn nativeHeaders
}
/*****************************
* Packaging
*****************************/
apply plugin: "maven"
// Workaround for Jenkins-Artifactory plugin not picking up the POM file
def pomFile = file("${buildDir}/libs/${archivesBaseName.toLowerCase()}-${version}.pom")
task newPom << {
pom {
project {
groupId project.group
artifactId project.name
version project.version
description = "Configuration Management Gradle Plugin"
}
}.writeTo(pomFile)
}
//disabling the install task since we're not using maven for real
install.enabled = false
//for publishing to artifactory via jenkins
if(project.hasProperty('artifactoryPublish')) {
artifactoryPublish {
mavenDescriptor pomFile
}
}
def filechange = file("build/libs/NativeJNI-${project.version}.so")
task copyfile(type: Copy) {
from 'build/binaries/mainSharedLibrary'
into 'build/libs'
include('libmain.so')
rename ('libmain.so', "$filechange")
}
//build.dependsOn copyfile
task build (dependsOn: ["newPom","copyfile"]) << {
println "build in progress"
}
def someFile = file("build/libs/NativeJNI-${project.version}.so")
artifacts {
archives someFile
}
Looks like this was a bug in 3.0,
https://github.com/GradleFx/GradleFx/issues/235

Resources