Issue
I am trying to create a Jar to be used as a Maven Repository
I have everything built out and all the classes are ready to go. Only problem is that the gradlew ./build is including the classes and resources from the test folder. I don't want these as part of the jar, especially the resource files under test.
So my question is, How do I exclude these files from my jar build task. I tried
tasks.named('jar'){
exclude('PATH/src/test/')
in my build.gradle but that didn't work
I am a newbiew at gradle and maven so any insight would help. Thanks!
Reference Material
build.gradle
plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'maven-publish'
}
group = 'com.project.tools'
version = '1.0.0'
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:31.0.1-jre'
implementation platform('io.cucumber:cucumber-bom:7.1.0')
implementation 'io.cucumber:cucumber-java'
implementation 'io.cucumber:cucumber-junit-platform-engine'
implementation 'io.cucumber:cucumber-junit'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
}
tasks.named('jar'){
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
}
}
File Structure
project/
├─ tools/
│ ├─ build/
│ │ ├─ classes/
│ │ │ ├─ new_folder/
│ │ │ │ ├─ main/
│ │ │ │ ├─ test/ #I Don't Want This Here, This Classes Do Not Need To Be Accessible
│ │ ├─ generated/
│ │ ├─ libs/
│ │ ├─ reports/
│ │ ├─ resources/
│ │ │ ├─ test/ #Would rather not have this entire folder
│ │ │ │ ├─ com.project.tools/
│ │ │ │ ├─ test.properties # Definitely Do Not Want This Included
│ │ ├─ test-results/
│ │ ├─ tmp/
│ ├─ src/
│ │ ├─ main/
│ │ │ ├─ java/
│ │ │ │ ├─ com.project.tools/
│ │ │ │ │ ├─ MyClasses.java
│ │ │ ├─ resources/
│ │ ├─ test/
│ │ │ ├─ java/
│ │ │ │ ├─ com.project.tools/
│ │ │ │ │ ├─ MyTestClasses.java
│ │ │ ├─ resources/
│ ├─ build.gradle
Solution
Gradle does the right thing by default, there is no need to manually exclude test
classes/resources from the jar
.
Answered By - user16358266
Answer Checked By - Mildred Charles (JavaFixing Admin)