Include file in a jar using gradle


(sakshi) #1

I am creating a distribution zip containing a jar as an output to my gradle task. I am using plugin project for creating the task. Now, in my gradle project(where I use this plugin), I get the jar zip as output and I want to customize that zip file so that in the gradle project, the user can add stuff as per the requirement. This means if the user needs some other files in the zip file, he should be able to do so without changing the task in the plugin project. I have tried a few solutions available but nothing seems to work so well. I have tried

jar{
baseName = 'distZip’
from(‘src/main/jni/’){
include(‘VC*.h’)
into(‘includes’)
}
manifest {
attributes ‘Implementation-Title’: ‘Analytics Library’, ‘Implementation-Version’: version
}

Another solution :
sourceSets.main.resources{
from(‘src/main/jni/’){
include(‘VC*.h’)
into(‘includes’)
}

Also, I used distribution plugin:
/apply plugin: 'java-library-distribution’
version 1.0
distributions{
jar{
baseName='distZip’
contents{
from(‘src/main/jni/’) {
include('VC
.h’)
into(‘includes’)
}
}
}
}

No solution seems to work till now. Any pointers


(Stefan Oehme) #2

You say you want to configure a zip, but all your examples are configuring the jar task. You probably wanted this (asuming your zip task is named myZip):

myZip {
  from ('src/main/jni')
  //more config...
}

But you might actually want to just apply the distribution plugin inside your custom plugin and in the buildscript do

distributions {
  myDist {
    from ('src/main/jni')
    //more config...
  }
}

That would automatically create a zip and a tar task for you.


(sakshi) #3

Yes, Thanks. I was using jar although that is not what I wanted to do. Thanks for the help!