D
D
defcore2018-02-24 17:21:41
Java
defcore, 2018-02-24 17:21:41

How to send classes of some (not all) libraries to binary in Gradle?

Initially, I needed the binary of my project to contain, in addition to my classes, also the classes of some libraries.
Found this solution for Gradle:

jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

But this does not suit me, because. this line sends the classes of absolutely all the libraries that I use to the binary and it turns out to be a garbage dump.
So, to the heart of the matter: how do I send the classes of only one library to my binary? For example, json-simple library classes (com.googlecode.json-simple', name: 'json-simple', version: '1.1.1)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2018-02-25
@defcore

Maybe so?

jar {
  from {
    configurations.compile.resolvedConfiguration.resolvedArtifacts.findAll {
      it.moduleVersion.id.with { it.group == 'com.googlecode.json-simple' && it.name == 'json-simple' }
    } collect {
      it.file.with { it.isDirectory() ? it : zipTree(it) }
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question