Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle project with only configuration and no sources

Tags:

gradle

build

I'd like to create a new Gradle project without any sources. I'm going to put there some configuration files and I want to generate a zip file when I build. With maven I'd use the assembly plugin. I'm looking for the easiest and lightest way to do this with Gradle. I wonder if I need to apply the java plugin even if I don't have any sources here, just because it provides some basic and useful tasks like clean, assemble and so on. Generating a zip is pretty straightforward, I know how to do that, but I don't know where and how to put the zip generation within the gradle world.

like image 764
javanna Avatar asked Dec 31 '25 22:12

javanna


2 Answers

I've done it manually until now. In other words, for projects where all I want to do is create some kind of distro and I need the basic lifecycle tasks like assemble and clean, I've simply created those tasks along with the needed dependencies.

But there is the 'base' plugin (mentioned under "Base plugins" of the "Standard Gradle Plugins" in the user's guide) that seems to fit the bill nicely for this functionality. Note though that the user guide mentions that this and the other base plugins are not yet considered part of the Gradle API and are not really documented.

The results are pretty much identical to yours, the only difference being that there are no confusing java specific tasks that always remain UP-TO-DATE.

apply plugin: 'base'

task dist(type: Zip) {
    from('solr')
    into('solr')
}

assemble.dependsOn(dist)

Sample run:

$ gradle clean assemble
:clean
:dist
:assemble

BUILD SUCCESSFUL

Total time: 2.562 secs
like image 142
David Resnick Avatar answered Jan 02 '26 11:01

David Resnick


As far as I understood, it might sound strange but looks like I need to apply the java plugin in order to create a zip file. Furthermore it's handy to have available some common tasks like for example clean. The following is my build.gradle:

apply plugin: 'java'

task('dist', type: Zip) {
    from('solr')
    into('solr')
}

assemble.dependsOn dist

I applied the java plugin and defined my dist task which creates a zip file containing a solr directory with the content of the solr directory within my project. The last line is handy to have the task executed when I run the common gradle build or gradle assemble, since I don't want to explicitly call the dist task. This way if I work with multiple projects I just need to execute gradle build on the parent to generate all the artifacts, including the configuration zip.

Please let me know if you have better solutions and add your own answer!

like image 31
javanna Avatar answered Jan 02 '26 10:01

javanna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!