[英]Exclude Test folder and Resources from Gradle Jar build
I am trying to create a Jar to be used as a Maven Repository我正在尝试创建一个 Jar 用作 Maven 存储库
I have everything built out and all the classes are ready to go.我已经建立了所有内容,并且所有课程都准备好了 go。 Only problem is that the gradlew./build is including the classes and resources from the test folder.唯一的问题是 gradlew./build 包含来自测试文件夹的类和资源。 I don't want these as part of the jar, especially the resource files under test.我不希望这些成为 jar 的一部分,尤其是被测资源文件。
So my question is, How do I exclude these files from my jar build task.所以我的问题是,如何从我的 jar 构建任务中排除这些文件。 I tried我试过了
tasks.named('jar'){
exclude('PATH/src/test/')
in my build.gradle but that didn't work在我的 build.gradle 但那不起作用
I am a newbiew at gradle and maven so any insight would help.我是 gradle 和 maven 的新手,所以任何见解都会有所帮助。 Thanks!谢谢!
Reference Material参考资料
build.gradle 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
Gradle does the right thing by default, there is no need to manually exclude test
classes/resources from the jar
. Gradle 默认做正确的事,无需手动从jar
中排除test
类/资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.