Using Gradle with v5.0.6

68 views
Skip to first unread message

Andy Bowes

unread,
Nov 14, 2015, 9:54:17 AM11/14/15
to izpack-user
I am trying to use IZPack with a Gradle build.  We have been using v4.3.5 but are now moving to v5.0.6.

In v4.3.5 we could use a the gradle izpack plugin to perform the compilation of the installer but v5.0.6 I need to get Gradle to invoke the Ant Task : com.izforge.izpack.ant.IzPackTask

I have the following Gradle task defined to invoke izPack via Ant:

task izPack {
    ant.taskdef(name: 'izPack', classname: 'com.izforge.izpack.ant.IzPackTask',
                classpath: configurations.izpack.asPath)

    ant.properties.applicationVersion = '0.9.1'
    ant.properties.izPackConfigDirectory = projectDir.path + '/src/main/izpack'
    ant.properties.installerArtifactsDirectory = buildDir.path + '/installerArtifacts'
    ant.properties.installerTasksJar = buildDir.path + "/libs/mesh-installer.jar"

    ant.izPack(input:projectDir.path + '/src/main/izpack/install.xml',
               output:buildDir.path + '/distributions/mesh-${meshVersion}-installer.jar',
               installerType:'standard',
               basedir:projectDir.path + '/src/main/izpack',
               inheritAll:true)
}

This mostly works but I am having problems injecting parameters into this Ant Task so that the can be substituted in the installer.xml.
ant.properties.applicationVersion = ‘0.9.1’
ant.properties.izPackConfigDirectory = projectDir.path + '/src/main/izpack'
ant.properties.installerArtifactsDirectory = buildDir.path + '/installerArtifacts'
ant.properties.installerTasksJar = buildDir.path + "/libs/mesh-installer.jar"

If I set the inheritAll flag to true on the izPackTask then I get the following error:
[ant:izPack] Exception in thread "Thread-3" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
[ant:izPack] at com.izforge.izpack.ant.IzpackAntRunnable.run(IzpackAntRunnable.java:67)
[ant:izPack] at java.lang.Thread.run(Thread.java:745)

It looks like Gradle is setting 1 or more project properties to be an Integer rather than a String and this is causing the issue within the IzpackantRunnableTask as it casts an Object to String without checking if this can be performed.  Is there a way to explicitly declare properties on the izPackTask rather than inheriting all of the properties from the project?

Thanks

Andy Bowes

unread,
Nov 16, 2015, 5:29:08 AM11/16/15
to izpack-user
I have modified the Gradle build script to attempt to use the Gradle Extra Properties feature so that the task now looks like:

task createInstallerJar {
    ant.taskdef(name: 'izPack', classname: 'com.izforge.izpack.ant.IzPackTask',
                classpath: configurations.izpack.asPath)

task createInstallerJar.doLast {
    ext.applicationVersion = meshVersion
    ext.izPackConfigDirectory = projectDir.path + '/src/main/izpack'
    ext.installerArtifactsDirectory = buildDir.path + '/installerArtifacts'
    ext.installerTasksJar = buildDir.path + "/libs/mesh-installer.jar"

    ant.izPack(input:projectDir.path + '/src/main/izpack/install.xml',
               output:buildDir.path + '/mesh-${meshVersion}-installer.jar',
               installerType:'standard',
               basedir:projectDir.path + '/src/main/izpack',
               inheritAll:false)


I am still seeing the following error message when running the izPack Compiler which seems to indicate that the value for the supplied property has not be substituted into the install.xml file.

com.izforge.izpack.api.exception.CompilerException: /home/spineii-user/spineii/dev/messageexchangeclient/mesh-installer/src/main/izpack/install.xml:69: /home/spineii-user/spineii/dev/messageexchangeclient/mesh-installer/src/main/izpack/@{installerArtifactsDirectory} not found.



René Krell

unread,
Dec 1, 2015, 7:10:44 AM12/1/15
to izpack-user
Hi Andy,

we are interested to get IzPack working in Gradle, but I haven't dealt much with it, to be honest.

To speak for Maven, the IzPack Maven plugin initializes Maven properties from a POM as so called "IzPack Properties", see org.izpack.mojo.IzPackNewMojo#initMavenProperties. This way references of type @{...} can be resolved, see https://izpack.atlassian.net/wiki/display/IZPACK/Properties. A second way is resolving them before launching the Izpack compiler by the Maven resources plugin filtering instead, after adding special filter definitions, and the result after filtering is to be parsed to the IzPack compiler.

For the IzPackAntTask I have to look at the code. There are two ways:
  1. Adding explicit nested <property> definitions to the task
  2. Inheriting Izpack properties from the Ant project properties.
In both ways I can't see any suspect conversion to and from types different from String, see com.izforge.izpack.ant.IzpackAntRunnable#run.
I don't know if this helps, but it describes the state as it is in 5.0.6.

René

René Krell

unread,
Dec 1, 2015, 7:30:18 AM12/1/15
to izpack-user
@Andy: For your case, you can add properties for resolving @{...} literals just by using com.izforge.izpack.ant.IzPackTask.addConfiguredProperty(Property property).
I'm not sure whether you're able to do so from Gradle.
R.
Reply all
Reply to author
Forward
0 new messages