2

Using gradle 3.4 but fairly new to it.

If I run gradlew installDist the files in src/main/java get copied to the build folder all that works fine.

But I also have an extra folder in src/main/conf I would like to copy over to build/install/my-artifact/conf

I don't want to put it in src/main/resources because that will get included inside the jar. I would like to keep it external.

My gradle file doesn't have anything special except the dependencies.

So how would I go about copying the folders/files when installDist runs?

EDIT:

Has to work with shadow plugin as well.

user432024
  • 4,392
  • 8
  • 49
  • 85

1 Answers1

4

To manage distribution contents, you will need to modify the main distribution like the following :

apply plugin: 'distribution'

distributions {
    main {
        baseName = 'my-artifact'
        contents {
            from { 'src/main/java' }
            from('src/main') {
                include 'conf/**'
            }
        }
    }
}

This will :

  • copy the files under src/main/java
  • copy the directory conf and the files under it

The new structure would be like :

build/install/my-artifact/
                   │
                   ├── com/
                   │   └── yourlib
                   │       └── ......
                   └── conf/
                       └── .....

You could also include the source directory at the same level :

build/install/my-artifact/
                   │
                   ├── java/
                   │    └── com/
                   │         └── yourlib
                   │               └── ......     
                   └── conf/
                        └── .....

with the following :

apply plugin: 'distribution'

distributions {
    main {
        baseName = 'my-artifact'
        contents {
            from('src/main') {
                include 'java/**'
                include 'conf/**'
            }
        }
    }
}

Check CopySpec interface for more info

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
  • Ok that seems to work. I wasn't sure if it's the same or not, but can this be done with the shadow versions installShadowApp and distShadowZip (updated question)? – user432024 Apr 20 '17 at 13:48
  • Did you try [that workaround](https://github.com/johnrengelman/shadow/issues/150) ? – Bertrand Martel Apr 20 '17 at 13:53
  • Yeah that works. installShadowApp { distributions { contents { from('src/main') { include 'conf/**' } from ('.') { include 'webroot/**' } } } } – user432024 Apr 20 '17 at 14:53