Gradle deployment fails with "java.io.IOException: The filename, directory name, or volume label syntax is incorrect"


(Jawann) #1

Hello, I’m trying to onboard a couple of new developers to get them working on our Java code, but I’m running into this error in Windows. All other Gradle commands work fine (clean project, clean dp, check dp, etc.), but our deployment command (dpDeployAll) fails. I followed the exact same setup process on 3 different Windows machines; the two machines running Windows 10 face this error, the machine running Windows 7 does not.

I’ve spent at least six hours looking into this unsuccessfully (cleaning project, rebuilding project, resyncing Gradle, reinstalling JDK, checking JAVA_HOME, deleting/reimporting project, etc.). I’m not a dev by training and have tapped out what I can do based on Googling similar issues. Can anyone help?

Hopefully it’s a quick answer for someone who actually knows what they’re doing. Thanks!

Here is the stacktrace:

$ gradle dpDeployAll -Phost=10.2.9.106 --stacktrace
:deploy:checkJavaVersion UP-TO-DATE
:deploy:compileJava UP-TO-DATE
:deploy:compileGroovy UP-TO-DATE
:deploy:processResources UP-TO-DATE
:deploy:classes UP-TO-DATE
:deploy:dpDeployAll

ChargeAdmin servlet version on 10.2.9.106 is 1.3.1

Using profile all_production
Exception in thread "main" java.io.IOException: The filename, directory name, or volume label syntax is incorrect
    at java.io.WinNTFileSystem.canonicalize0(Native Method)
    at java.io.Win32FileSystem.canonicalize(Win32FileSystem.java:414)
    at java.io.File.getCanonicalPath(File.java:618)
    at java_io_File$getCanonicalPath$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at deploy.Deploy$_runDeploy_closure7.doCall(Deploy.groovy:164)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
    at groovy.lang.Closure.call(Closure.java:414)
    at groovy.lang.Closure.call(Closure.java:430)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2030)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2015)
    at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2056)
    at org.codehaus.groovy.runtime.dgm$162.invoke(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at deploy.Deploy.runDeploy(Deploy.groovy:161)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
    at deploy.Deploy.runDeployProfile(Deploy.groovy:144)
    at deploy.Deploy.run(Deploy.groovy:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at deploy.Deploy.main(Deploy.groovy:335)
:deploy:dpDeployAll FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':deploy:dpDeployAll'.
> Process 'command 'C:\Program Files\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':deploy:dpDeployAll'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_80\bin\java.exe'' finished with non-zero exit value 1
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:369)
    at org.gradle.process.internal.DefaultJavaExecAction.execute(DefaultJavaExecAction.java:31)
    at org.gradle.api.tasks.JavaExec.exec(JavaExec.java:74)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
    ... 70 more


BUILD FAILED

Total time: 4.258 secs

And here is the build.gradle file:

apply plugin: 'base'

subprojects {
    ext.LIBSOCKET_CAN_JAVA_VERSION = '1.0.2'
    ext.J2MOD_VERSION = '2.3.3'

    // Versions which are installed on the EuroTech boxes
    ext.KURA_API_VERSION = '1.0.7'
    ext.EQUINOX_IO_VERSION = '1.0.400.v20120522-2049'
    ext.SLF4J_VERSION = '1.6.4'
    ext.OSGI_SERVICES_VERSION = '3.3.100.v20120522-1822'
    // Guava 21 requires Java 8 so we are stuck on 20 for now.
    ext.GUAVA_VERSION = '20.0'
    ext.GUAVA_RETRYING_VERSION = '2.0.0'
    ext.JUNIT_VERSION = '4.12'
    ext.COMMONS_LANG_VERSION = '3.4'
    ext.COMMONS_FILEUPLOAD_VERSION = '1.2.2.v20111214-1400'
    ext.COMMONS_IO_VERSION = '2.4.0'
    ext.JAVAX_SERVLET_VERSION = '3.0.0.v201112011016'
    ext.OSGI_CMPN_VERSION = '4.3.0.201111022214'
    ext.ECLIPSE_OSGI_VERSION = '3.8.1.v20120830-144521'
    ext.DEPLOYMENT_AGENT_VERSION = '1.0.6'
    ext.APACHE_COMMONS_MATH_VERSION = '3.6.1'
    ext.MOCKITO_VERSION = '2.7.22'

    apply plugin: 'java'
    // The EuroTech device runs Java 1.7, so we have to build to that.
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7

    repositories {
        jcenter()
        maven {
            // Needed for Kura
            url 'https://repo.eclipse.org/content/repositories/releases/'
        }
        maven {
            // Needed for Eclipse OSGI.
            url 'http://dist.wso2.org/maven2/'
        }
        maven {
            // Needed for some EuroTech-required JARs that aren't anywhere else.
            url 'https://raw.github.com/eurotech/kura_addons/mvn-repo/'
        }
        maven {
            // For inamik-text-tables
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }

    task checkJavaVersion() {
        if (!JavaVersion.current().isJava7()) {
            String message = "ERROR: Java 1.7 required but " +
                    JavaVersion.current() + " found."
            throw new IllegalStateException(message)
        }
    }

    compileJava.dependsOn checkJavaVersion
}

// Tool-specific configuration
configure([project(':com.projectfw.charge.tools.j2mod.client'),
           project(':com.projectfw.charge.tools.j2mod.server')]) {

    apply plugin: 'application'

    run {
        if (project.hasProperty('exec.args')) {
            args project.getProperty("exec.args").split()
        }
    }
}

// OSGI-specific configuration

static def createOsgiVersionedPackageList(deps) {
    def out = []
    for (def dep : deps) {
        // For now, ignore versioning constraints because we are rapidly revving version numbers,
        // and the default behavior prevents us from revving a major version of common without
        // rebuilding and redeploying everything.  Longer-term, this is what we want, but for now it
        // is annoying.  This line suppresses that behavior by allowing dependencies to be resolved
        // by any version, not just versions that should be suitable by the rules of semantic versioning.
        out.add(dep.name + ';version="[0,9999)"')
    }
    return out.join(',')
}

configure([project(':com.projectfw.charge.3rdpartydeps'),
           project(':com.projectfw.charge.accelerometermanagerimpl'),
           project(':com.projectfw.charge.belfusemanagerimpl'),
           project(':com.projectfw.charge.bmsmanagerimpl'),
           project(':com.projectfw.charge.canconnectorimpl'),
           project(':com.projectfw.charge.canphysicalsocket'),
           project(':com.projectfw.charge.cloudcommandmanager'),
           project(':com.projectfw.charge.cloudpayloaduploader'),
           project(':com.projectfw.charge.common'),
           project(':com.projectfw.charge.display'),
           project(':com.projectfw.charge.energyaccumulatorl2genimpl'),
           project(':com.projectfw.charge.errorwatchdogl2genimpl'),
           project(':com.projectfw.charge.gpsmanagerimpl'),
           project(':com.projectfw.charge.gpiomanagerl2genimpl'),
           project(':com.projectfw.charge.gpiomanagerl2hecoimpl'),
           project(':com.projectfw.charge.legacytelemetryl2genimpl'),
           project(':com.projectfw.charge.chargeadmin'),
           project(':com.projectfw.charge.modbusconnectorimpl'),
           project(':com.projectfw.charge.modbusmanagerl2genimpl'),
           project(':com.projectfw.charge.modbusmanagerl3chademoimpl'),
           project(':com.projectfw.charge.modbusphysicaldevice'),
           project(':com.projectfw.charge.statemachinel2hecoimpl'),
           project(':com.projectfw.charge.statemachinel2genimpl'),
           project(':com.projectfw.charge.statemachinel3chademoimpl'),
           project(':com.projectfw.charge.statemachinelegacyl2impl'),
           project(':com.projectfw.charge.unitconfigurationimpl'),
           project(':com.projectfw.charge.userinputsimpl'),
           project(':com.projectfw.charge.veecanmanagerimpl'),

           project(':com.projectfw.charge.tools.gpiotool')]) {

    apply plugin: "jacoco"

    apply plugin: 'osgi'

    jar {
        manifest {
            instruction 'Service-Component', 'OSGI-INF/*.xml'
            instruction 'Bundle-ActivationPolicy', 'lazy'
        }
        into('OSGI-INF') {
            from "${projectDir}/OSGI-INF"
        }
        // This ensures we have any necessary 3rd-party dependencies in our JAR.
        into('lib') {
            from "${projectDir}/lib"
        }
    }

    afterEvaluate { project ->
        jar {
            manifest {
                def fw_dependencies = project.configurations.runtime.getAllDependencies().withType(ProjectDependency)
                instruction 'Import-Package', createOsgiVersionedPackageList(fw_dependencies) + ',*'
                instruction 'Bundle-Classpath', '.'
                instruction 'Bundle-Vendor', project.bundleVendor
                symbolicName = project.name + ';singleton:=true'
            }
        }
    }

    test {
        testLogging {
            exceptionFormat = 'full'
        }
        finalizedBy jacocoTestReport
    }

    task dp(dependsOn: jar) {
        def outputPath = "$buildDir/distributions"
        // Used to compute if this task needs to be re-run.
        outputs.dir outputPath
        inputs.files jar.outputs

        doLast {
            def tempDir = getTemporaryDir()
            def bundlesDirRelativePath = 'bundles'
            def manifestRelativePath = "META-INF/MANIFEST.MF"
            def manifestFullPath = "$tempDir/$manifestRelativePath"

            // The deployment package manifest file is really simple, since we only include one
            // bundle per .dp file.  For this reason, we can just inline write out the minimum
            // MANIFEST.MF contents here.
            def manifestContents = new StringBuilder()
            manifestContents.append("Manifest-Version: 1.0\n")
            manifestContents.append("DeploymentPackage-SymbolicName: ${project.name}\n")
            manifestContents.append("DeploymentPackage-Version: ${version}\n")
            manifestContents.append("\n")
            manifestContents.append("Name: bundles/${jar.archiveName}\n")
            manifestContents.append("Bundle-SymbolicName: ${project.name};singleton:=true\n")
            manifestContents.append("Bundle-Version: ${version}\n")

            delete tempDir
            file(outputPath).mkdirs()
            file("$tempDir/META-INF").mkdirs()
            file("$tempDir/$bundlesDirRelativePath").mkdirs()
            file(manifestFullPath).write(manifestContents.toString())
            def archiveName = jar.archiveName.replace('.jar', '.dp')
            copy {
                from "${jar.destinationDir}/${jar.archiveName}"
                into "$tempDir/$bundlesDirRelativePath/"
            }

            delete "$outputPath/$archiveName"
            // Must use ant zip task because it supports the 'filesonly' parameter we need.
            // Deployment Packages are strange in that they don't allow directory entries in the zipfile.
            ant.zip(destfile: "$outputPath/$archiveName", filesonly: true) {
                fileset(dir: tempDir) {
                }
            }
        }
    }
}

Edit: adding deploy.gradle file:

version '3.8.0'

apply plugin: 'groovy'

dependencies {
    compile localGroovy()
    compile group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder', version: '0.7'
    compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.3'
    compile group: 'com.github.inamik.text.tables', name: 'inamik-text-tables', version: '1.0-SNAPSHOT'
    compile group: 'org.eclipse', name: 'org.eclipse.osgi', version: ECLIPSE_OSGI_VERSION
}

['dpDeployAll', 'dpDeploy', 'dpDeployAllCustom', 'dpList', 'dpUninstall', 'dpUninstallAll'].each { name ->
    //noinspection GroovyAssignabilityCheck
    task "$name"(type: JavaExec) {
        classpath = sourceSets.main.runtimeClasspath
        main = 'deploy.Deploy'
        //noinspection GrUnresolvedAccess
        doFirst {
            if (project.hasProperty('host')) {
                arguments.add(0, project.getProperty('host'))
            } else {
                throw new InvalidUserDataException("Missing host property: specify with \"-Phost=hostname\"")
            }
            //noinspection GrUnresolvedAccess,GroovyAssignabilityCheck
            args arguments
        }
    }
}

dpDeployAll {
    doFirst {
        ext.arguments = ['deploy_all']
        arguments += ['all_production']
    }
}


dpDeploy {
    doFirst {
        ext.arguments = ['deploy']
        if (project.hasProperty('package')) {
            def packageName = project.getProperty('package')
            arguments += [packageName]
        } else {
            throw new InvalidUserDataException("Missing packageName property: specify with \"-Ppackage=package\"")
        }
    }
}

dpDeployAllCustom {
    doFirst {
        ext.arguments = ['deploy_all']
        if (project.hasProperty('profile')) {
            def profile = project.getProperty('profile')
            arguments += [profile]
        } else {
            throw new InvalidUserDataException("Missing profile property: specify with \"-Pprofile=profile\"")
        }
    }
}

dpUninstall {
    doFirst {
        ext.arguments = ['uninstall']
        if (project.hasProperty('package')) {
            def packageName = project.getProperty('package')
            arguments += [packageName]
        } else {
            throw new InvalidUserDataException("Missing packageName property: specify with \"-Ppackage=package\"")
        }
    }
}

dpUninstallAll {
    doFirst {
        ext.arguments = ['uninstall_all']
    }
}

dpList {
    doFirst {
        ext.arguments = ['list']
    }
}

Edit: adding readme for dpDeployAll. all_production.txt lists all the individual packages (com.projectfw.mobi.whatever).

## dpDeployAll

Deploys the deployment packages specified in the `all_production.txt`
profile to the specified host.

The deployment packages will be retrieved from the `build/distributions`
subdirectory within the package directory for each package.  If multiple
deployment packages for a given package exist in this location, the one
with the highest version number will be used.

If a package does not already exist on the target host, it will be
deployed.

If a package already exists on the target host, but its version is different
than the highest local version, it will be replaced.

If a package already exists on the target host with an identical version
number to the highest local version, and the version contains the string
`dev` in its qualifier, it will be replaced no matter what.
For example: `3.1.2.dev`.

If packages exist on the device which are not specified in the package
profile, they will be uninstalled.

```
gradle dpDeployAll -Phost=<host>
```