簡體   English   中英

從 Gradle Jar 版本中排除測試文件夾和資源

[英]Exclude Test folder and Resources from Gradle Jar build

我正在嘗試創建一個 Jar 用作 Maven 存儲庫

我已經建立了所有內容,並且所有課程都准備好了 go。 唯一的問題是 gradlew./build 包含來自測試文件夾的類和資源。 我不希望這些成為 jar 的一部分,尤其是被測資源文件。

所以我的問題是,如何從我的 jar 構建任務中排除這些文件。 我試過了

tasks.named('jar'){
    exclude('PATH/src/test/')

在我的 build.gradle 但那不起作用

我是 gradle 和 maven 的新手,所以任何見解都會有所幫助。 謝謝!

參考資料

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)
    }
}

文件結構

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 默認做正確的事,無需手動從jar中排除test類/資源。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM