Saket Singh
Saket Singh

Reputation: 63

How to include only specific files from the main/java to be part of jar to be published to using gradle?

I don't want the whole main/java to be pushed as Jar

Instead, I want only specific folders inside main/java to be part of the jar.

How do I achieve it?

Upvotes: 0

Views: 1177

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14493

Actually, this part of your build.gradle has nothing to do with creating the JAR file. It just defines a publication that refers to the Java component built by your Java project. One part of this Java project is the task jar, which actually creates the JAR file. This task is of type Jar, so it offers methods to either exclude files following a pattern or to only include files following a pattern:

jar {
    include '**/path/to/included/files/*.class'
    // alternatively
    exclude '**/path/to/excluded/files/*.class'
}

Upvotes: 1

Related Questions