簡體   English   中英

如何在Gradle中設置構建以不將JUnit測試用例部署到JBoss AS 7.1

[英]How to setup a build in Gradle to not deploy JUnit test cases to JBoss AS 7.1

我有一個非常簡單的JSF2應用程序,它僅顯示一個hello world頁面。 問題在於此應用程序具有JUnit測試用例。 當構建war文件以將其部署在JBoss AS 7.1中時,測試類將隨它一起使用,從而在加載應用程序時引起一些問題。

build.gradle文件在下面

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'application'
apply plugin: 'war'

sourceCompatibility = 1.7
targetCompatibility = 1.7

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

// Needed in order to make the test running to work
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
sourceSets.test.output.classesDir = sourceSets.main.output.classesDir
sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir

def hibernateVersion = "4.3.7.Final"
def weldVersion = "1.1.27.Final"
def unidadesVersion = "1.0.0"
def demoiselleVersion = "2.4.1"
def arquillianVersion = "1.1.5.Final"

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    runtime 'javax.servlet:javax.servlet-api:3.1.0'
    runtime 'javax.enterprise:cdi-api:1.0-SP1'
    runtime 'org.jboss:jandex:1.2.2.Final'

    testCompile 'junit:junit:4.11'
    testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:'+arquillianVersion    
    testCompile 'br.gov.frameworkdemoiselle.component:demoiselle-junit:2.3.1'
}

eclipse {
    wtp {
        facet {
            facet name: "java", version: "1.7"          // Java version
            facet name: "jst.web", version: "3.0"       // Dynamic Web Application
            facet name: "jst.jsf", version: "2.2"       // Java Server Faces
            facet name: "wst.jsdt.web", version: "1.0"  // JavaScript
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

在我的測試中,我執行了一些依賴注入,這就是為什么在測試依賴中包含WeldJandex的原因。

我期望如此,因為測試用例位於src / test / java中,所以它們不會包含在war文件中,但是似乎我錯了!

我想念什么? 如何從戰爭中排除那些文件?

更新1

按照Peter Niederwieser的建議操作后, build.gradle文件如下所示

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'application'
apply plugin: 'war'

sourceCompatibility = 1.7
targetCompatibility = 1.7

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

def hibernateVersion = "4.3.7.Final"
def weldVersion = "1.1.27.Final"//"2.2.7.Final" Demoiselle 2.4.1 não é compatível com Weld 2
def unidadesVersion = "1.0.0"
def demoiselleVersion = "2.4.1"
def arquillianVersion = "1.1.5.Final"

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.jboss.weld.se:weld-se-core:'+weldVersion

    runtime 'javax.servlet:javax.servlet-api:3.1.0'
    runtime 'javax.enterprise:cdi-api:1.0-SP1'
    runtime 'org.jboss:jandex:1.2.2.Final'
    runtime 'org.slf4j:slf4j-log4j12:1.7.7'

    testCompile 'junit:junit:4.11'
}

war {
}

eclipse {
    wtp {
        facet {
            facet name: "java", version: "1.7"          // Java version
            facet name: "jst.web", version: "3.0"       // Dynamic Web Application
            facet name: "jst.jsf", version: "2.2"       // Java Server Faces
            facet name: "wst.jsdt.web", version: "1.0"  // JavaScript
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

這就是我的Eclipse項目的樣子

在此處輸入圖片說明

這就是JBoss AS 7.1部署文件夾包含的內容

在此處輸入圖片說明

上圖顯示了/src/test/java下的文件夾已包含在戰爭中並已部署在JBoss中。

更新2

我查看了build\\lib生成的war文件。 它不包含任何測試類,因此我相信JBoss面板會執行完整的構建,並包含它在另一場戰爭中可以編譯然后部署的所有內容。

因此,我相信war插件可以正常工作,而不是部署任何測試文件。

先生繼續!

更新3

經過一些額外的學習,我終於可以理解發生了什么。 在運行任何Gradle任務(例如Gradle clean ,Gradle將條目添加到Eclipse的Deployment Assembly中 該條目正是test classes文件夾。 這樣的條目,JBoss發布代理將始終部署src/test/java以下的任何內容。

因此,解決問題的一種方法是打開項目“屬性”窗口,然后從那里手動刪除該條目。 但是,Gradle是關於自動化構建和配置的,因此我希望能夠配置Gradle構建以使其不在此處添加此類條目。

有任何想法嗎?

該行有效地將測試類轉換為生產類: sourceSets.test.output.classesDir = sourceSets.main.output.classesDir 刪除此行,不需要它。

暫無
暫無

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

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