![](/img/trans.png)
[英]How to setup a Gradle build for a JSF2 application to be hosted by 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'
}
在我的测试中,我执行了一些依赖注入,这就是为什么在测试依赖中包含Weld和Jandex的原因。
我期望如此,因为测试用例位于src / test / java中,所以它们不会包含在war文件中,但是似乎我错了!
我想念什么? 如何从战争中排除那些文件?
按照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中。
我查看了build\\lib
生成的war文件。 它不包含任何测试类,因此我相信JBoss面板会执行完整的构建,并包含它在另一场战争中可以编译然后部署的所有内容。
因此,我相信war插件可以正常工作,而不是部署任何测试文件。
先生继续!
经过一些额外的学习,我终于可以理解发生了什么。 在运行任何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.