smeeb
smeeb

Reputation: 29567

Gradle Copy task only doing partial copy

I have a Gradle "deploy" task that copies a JAR and all the contents of a "config" folder to an intended destination. My project directory structure looks like:

myapp/
    src/main/java/
        <java sources>
    config/
        <lots of stuff>
    build.gradle
    settings.gradle

And my deploy task looks like:

task deploy(type: Copy, overwrite: true) {
    from('build/libs')
    into('/Users/myuser/myapp/deploy/myapp')
    include('myapp.jar')

    from('config')
    into('/Users/myuser/myapp/deploy/myapp')
    include('config/**')
}

When I run ./gradle build deploy, I see the JAR getting copied to /Users/myuser/myapp/deploy/myapp, but not the config directory (nor all of its subdirectories and contents). The desired end result is a /Users/myuser/myapp/deploy/myapp directory that looks like:

/Users/myuser/myapp/deploy/myapp/
    myapp.jar
    config/
        <lots of stuff>

Furthermore, the idea is that this copy should be "drop n' swap", particularly for the config directory. That is, regardless of what is currently in the /Users/myuser/myapp/deploy/myapp/config directory, when I run deploy, those contents are completely replaced by whatever is in the config/ directory of my project.

UPDATE

I have created a GitHub repo to demonstrate the issue. Simply follow the instructions to reproduce.

Any ideas where I'm going awry?

Upvotes: 3

Views: 318

Answers (2)

RaGe
RaGe

Reputation: 23795

  • To directly answer your question:

    task deploy(type: Copy, overwrite: true){
        from ("$buildDir/libs"){include('gradlecopyexample.jar')}
        from ("$rootDir"){include('config/**')}
        into("$buildDir/deploy")
    }
    
  • However, I still am of the opinion that the gradle application plugin is a good fit for your usecase. Instead of having the config folder in the root directory, place it under src/dist, Then running gradle installDist (or distZip) will include your config folder with the distribution package.

Upvotes: 1

Stanislav
Stanislav

Reputation: 28136

I suppose, the reason is include('config/**'), which should include something like config/config/**, where ** is all subdirectories, but not all the files under config/ directory.

Try to make it as follows:

task deploy(type: Copy, overwrite: true) {
    from('build/libs')
    into('/Users/myuser/myapp/deploy/myapp')
    include('myapp.jar')

    into('/Users/myuser/myapp/deploy/myapp')
    include('config/**')
}

Upvotes: 1

Related Questions