0

Now this may be a bit weird but hear me out.
I need to include some jar files (as they are without unpacking them) into a jar file I'm generating with gradle.

I need it so I can unpack them when needed later. (Why exactly I need that is a different story that's not relevant here.)

Now so far I have this:

configurations {
    slf4j
}

dependencies {
    slf4j "org.slf4j:slf4j-api:${slf4j_version}"
    slf4j "org.slf4j:slf4j-jdk14:${slf4j_version}"
}

jar {
    from(project.configurations.slf4j.files) {
        into ("slf4j_jars")
    }
}

This works almost, but with that gradle unpacks the jar files so the class files themselves end of in my jar and not the SLF4J jars as I would like to have.
And the jar files should end of in the slf4j_jars folder inside of my jar.

Update:

configurations {
    slf4j
}

dependencies {
    slf4j "org.slf4j:slf4j-api:${slf4j_version}"
    slf4j "org.slf4j:slf4j-jdk14:${slf4j_version}"
}

processResources {
    from(project.configurations.slf4j.files) {
        into ("slf4j_jars")
    }
}

Behaves the same and so does putting the files directly in the src/main/resources/slf4j_jars folder.

For some reason Gradle always unpacks the jar files.

Also I am using Gradle 4.10.3 and sadly can't upgrade to any 5.x.x version.

Update 2:

I managed to at least get the files themselves in with this:

configurations {
    slf4j
}

dependencies {
    slf4j "org.slf4j:slf4j-api:${slf4j_version}"
    slf4j "org.slf4j:slf4j-jdk14:${slf4j_version}"
}

processResources {
    from(project.configurations.slf4j.files) {
        into "slf4j_jars"
        rename '(.*).jar', '$1.zip'
    }
}

Now they have been renamed to .zip files, which I can work around.

BrainStone
  • 3,028
  • 6
  • 32
  • 59
  • I just tried your first snippet with Gradle 4.2.1 and 5.6.4, and it worked perfectly in both cases. Maybe your build is being messed up by a custom plugin or something? – barfuin Nov 04 '19 at 14:43
  • That’s a possibility I actually did not consider. I’ll verify that later myself. – BrainStone Nov 04 '19 at 14:45

0 Answers0