Make two installDist tasks available?

I want to be able to do an installDist (from the application plugin) to the standard location (build/install), but also (for a production deployment) to a production location with a different path.

How would I do this? My attempts at this can be seen here.

The installDist task is a Sync task with the name installDist. The only difference between a Sync task and a Copy task is that Sync removes files in the destination first rather than just copying them. The application plugin adds logic to make sure that the the Sync task doesn’t obliterate the destination if there’s existing files that don’t look like an installed distribution.


The answer is posted on Stack Overflow, but here’s some additional explanations:

task deployOperativeVersion{
    installDist{
        destinationDir = file( "$operativeDir/$version" )
    }
}

Creates a deployOperativeVersion task. The task does nothing. installDist is not a property, so Groovy delegation causes the configurtion of the installDist task. Nothing will happen when you run deployOperativeVersion, but installDist will write to the file( "$operativeDir/$version" ) location.


task deployOperativeVersion{
    doFirst {
        installDist {
            destinationDir = file("$operativeDir/$version")
        }
    }
}

Creates a deployOperativeVersion task that configures the installDist task at execution. installDist will write to the file( "$operativeDir/$version" ) location only if both tasks are run and deployOperativeVersion runs first. Otherwise, installDist will write in the usual location.


task deployOperativeVersion{
    dependsOn installDist{ destinationDir=file("$productionDir/$version")
}

Creates a deployOperativeVersion task. The task does nothing. installDist is not a property, so Groovy delegation causes the configurtion of the installDist task, but the return value of this configuration is still the task, so the task dependency is added. deployOperativeVersion still does nothing, but installDist will run due to the dependency and write to the file( "$operativeDir/$version" ) location.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':installDist'.
> The specified installation directory '/home/mike/IdeaProjects/JavaFXExp2/Organiser/build/install' is neither empty nor does it contain an installation for 'Organiser'.
  If you really want to install to this directory, delete it and run the install task again.
  Alternatively, choose a different installation directory.

… needless to say, this is NOT the case: under …Organiser/build/install there is one directory only, Organiser, with /bin and /lib directories under it.

Your text here says that the directory structure is:

Organiser/build/install/Organiser
                              |- /bin
                              |- /lib

This error is correct in what it’s saying. It’s looking for an installation of Organiser, which is just the bin/ and lib/ directories. However, you have an Organiser folder in the build/install directory. That extra directory is the issue. The directory is not empty (has an Organiser folder`) and that thing it directly contains is not the installation. It’s not recursively looking to see if the only meaningful thing in a nested directory structure is eventually a distribution. It’s just looking for what would normally be expected unless something is incorrect.