Configure distribution artifacts


(Juhan) #1

Just started using Gradle first time and I am finding it difficult find information in the User Guide. Perhaps somebody can help me here.

So in my project, I am using Application plugin which itself uses Distribution plugin (firstly, already this is so confusing - how to find out what plugin is using what). So the application plugin is building me Jar along with Zip and Tar. The last two I do not need. How to configure, that my distribution artifacts is only the Jar file?


(Carlo Luib-Finetti) #2

Read Chapter 30 on publishing Artifacts.

What you want can be as simple as this:

task myJar(type: Jar)

artifacts {
archives myJar
}


(Juhan) #3

This did not make any sense to me.

What I have so far, is I use shadowJar plugin (com.github.jengelman.gradle.plugins:shadow:1.2.3) in my project. And in Jenkins I have gradle plugin + artifactory plugin, which handles the deployment of artifacts to Artifactory.

The shadowJar will be able to create fat Jar, which I need to deploy as well. So to enable it, I have configured:
artifacts {
archives shadowJar
}

But this configuration does not remove zip and tar distribution in my build life cycle.


(Janito Vaqueiro Ferreira Filho) #4

If you don’t want the archives to be created in your build lifecycle, I think the easiest solution would be to disable the tasks that create them:

distTar.enabled = false
distZip.enabled = false

That said, are you sure you need the application plugin? The purpose of the plugin (AFAICT) is to:

  • configure the Jar to be executable (by setting the main class)
  • generate platform specific distributions (ie. the zip and tar archives) for the Java application
  • add an install and a run task to the build to help installing and running the resulting application in your local machine using Gradle

If you’re only distributing (or deploying) the fat Jar, I think there might be no need for the application plugin. You can just configure the Jar to be executable manually:

shadowJar {
    attributes 'Main-Class': 'my.main.Class'
}

If you need to, you can also configure a run task manually using the JavaExec task type.


(Juhan) #5

Thanks!
distTar.enabled = false is what I tested before but installing the archives to local repo failed becuse it started to look for the tar file.

I could not configure shadowJar main class with that way. I use it together with the Application plugin for this purpose. I only used it because so was instructed on shadowJar doc.

I will try the JavaExec configuration.

EDIT: JavaExec is aparently not what I’m looking for. And seems like there is no other way to define main class in shadowJar :frowning:

EDIT: got it working!
jar{
manifest {
attributes ‘Main-Class’: ‘com.kambi.emct.Application’
}
}