我正在尝试将集成测试添加到一个大型Maven项目中。以下是所需的事件顺序:
除了步骤#9(因此出现了问题)之外,所有这些都按预期工作。相反,构建目录仍然设置为Clover版本,并且项目名称附加了“-clover”。我还发现,当“MyProject-clover.war”由Tomcat7托管时,它无法按预期运行(在浏览器中返回404错误)。
即使它确实有效,我们也不需要/希望在我们正在测试的WAR文件中使用Clover检测,因为集成测试不会触及任何生产代码(src/test/java下的所有Selenium UI内容都与本地托管的页面而不是生产代码本身)。
如前所述,这是一个包含数百个依赖项和数十个插件的大型项目。我相信以下内容与我的问题相关,尽管我可以在必要时挖掘更多(发布整个pom文件似乎不合理)。
这是Clover插件的pom配置:
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.1.11</version>
<configuration>
<generateHtml>true</generateHtml>
<generateXml>true</generateXml>
<licenseLocation>${basedir}/src/test/resources/clover.license</licenseLocation>
<targetPercentage>92%</targetPercentage>
<excludes>
<exclude>**/mock/*.java</exclude>
<exclude>**/com/mycompany/somestuff/*.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>generate-clover-report</id>
<phase>test</phase>
<goals>
<goal>instrument</goal>
<goal>clover</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
这是WAR插件的pom配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<!--Implementation-Build>${buildNumber}_${timestamp}</Implementation-Build -->
<Build-Time>${timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
以下是 Tomcat7 插件的 pom 配置:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<ajpPort>8009</ajpPort>
<backgroundProcessorDelay>2</backgroundProcessorDelay>
<configurationDir>${project.build.directory}/tomcat7_plugin</configurationDir>
<contextFile>${CATALINA_HOME}/conf/context.xml</contextFile>
<contextReloadable>false</contextReloadable>
<fork>true</fork>
<hostName>localhost</hostName>
<httpsPort>8443</httpsPort>
<ignorePackaging>false</ignorePackaging>
<jarScanAllDirectories>false</jarScanAllDirectories>
<path>/contentmain</path>
<port>8080</port>
<serverXml>${CATALINA_HOME}/conf/server.xml</serverXml>
<tomcatUsers>${CATALINA_HOME}/conf/tomcat-users.xml</tomcatUsers>
<tomcatWebXml>${CATALINA_HOME}/conf/web.xml</tomcatWebXml>
<useNaming>true</useNaming>
<useTestClasspath>true</useTestClasspath>
<update>true</update>
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war-only</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
以下是我运行“mvn全新安装-Dmaven.clover.skip”时的当前(期望)行为:
[INFO] --- maven-clover2-plugin:3.1.11:check (generate-clover-report) @ MyProject ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) @ MyProject ---
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes css/*.css and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes scripts/*/*.* and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes images/*.* and excludes:null
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [mydir/MyProject/target/MyProject]
[INFO] Processing war project
[INFO] Copying webapp resources [mydir/MyProject/src/main/webapp]
[INFO] Webapp assembled in [2019 msecs]
[INFO] Building war: /mydir/MyProject/target/MyProject.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] >>> maven-source-plugin:2.2.1:jar (default) @ MyProject >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy (default) @ MyProject ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.1:create-timestamp (default) @ MyProject ---
[INFO]
[INFO] <<< maven-source-plugin:2.2.1:jar (default) @ MyProject <<<
[INFO]
[INFO] --- maven-source-plugin:2.2.1:jar (default) @ MyProject ---
[INFO] Building jar: /mydir/MyProject/target/MyProject-sources.jar
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) @ MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
下面是我运行“mvn全新安装”时的当前(不希望的)行为(注意maven-war-plugin列出的路径和maven-source-plugin的警告消息:
[INFO] --- maven-clover2-plugin:3.1.11:check (generate-clover-report) @ MyProject ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) @ MyProject ---
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes css/*.css and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes scripts/*/*.* and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes images/*.* and excludes:null
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [mydir/MyProject/target/clover/MyProject-clover]
[INFO] Processing war project
[INFO] Copying webapp resources [mydir/MyProject/src/main/webapp]
[INFO] Webapp assembled in [1770 msecs]
[INFO] Building war: /mydir/MyProject/target/clover/MyProject-clover.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] >>> maven-source-plugin:2.2.1:jar (default) @ MyProject >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy (default) @ MyProject ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.1:create-timestamp (default) @ MyProject ---
[INFO]
[INFO] <<< maven-source-plugin:2.2.1:jar (default) @ MyProject <<<
[INFO]
[INFO] --- maven-source-plugin:2.2.1:jar (default) @ MyProject ---
[WARNING] NOT adding sources to artifacts with classifier as Maven only supports one classifier per artifact. Current artifact [com.mycompany:MyProject:war:clover:ParentProject-SNAPSHOT] has a [clover] classifier.
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) @ MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
在分叉生命周期的测试阶段,在Clover执行完maven-clover2-plugin:check goal之后,如何确保{project.build.directory}和{project.build.finalName}值被重置为其原始值?
我已经试过浏览Clover、WAR插件和Tomcat7的在线手册。我没有看到任何关于我可以用来恢复被Clover改变的构建变量的设置。我总是可以在我的pom文件中硬编码路径,但是我更喜欢不那么脆弱的解决方案。
事实证明,Clover总是会改变这些变量,除非使用clover2:setup目标。然而,如果你仍然希望岔开Clover的生命周期(即:clover2:instrument或clover2:instrument-test ),那么这些变量将总是被改变。
我们希望继续使用三叶草:仪器测试来分叉生命周期,所以我想出了一个解决方法。我没有使用project.build.finalName和project.build.directory变量,而是使用我自己的变量,这些变量在三叶草破坏它们之前被复制并保存在Maven执行中:
<properties>
<!-- Saving these variables now before Clover alters them -->
<original.build.finalName>${project.build.finalName}</original.build.finalName>
<original.build.directory>${project.build.directory}</original.build.directory>
</properties>
然后我告诉所有后续插件使用这些变量,而不是Clover更改的项目变量:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<cacheFile>${original.build.directory}/war/work/webapp-cache.xml</cacheFile>
<outputDirectory>${original.build.directory}</outputDirectory>
<warName>${original.build.finalName}</warName>
<webappDirectory>${original.build.directory}/${original.build.finalName}</webappDirectory>
<workDirectory>${original.build.directory}</workDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<configurationDir>${original.build.directory}/tomcat7_plugin</configurationDir>
<warDirectory>${original.build.directory}/${original.build.finalName}</warDirectory>
</configuration>
</plugin>
</plugins>
替代解决方案可能包括在随后的 Maven 阶段创建或使用其他插件,以便在 Clover 完成执行后还原 project.build 变量。这两种解决方案中的任何一种都可能比在所有插件中对路径进行硬编码更好。
[INFO]-maven-source-plugin:2 . 2 . 1:jar(默认)@ MyProject - [WARNING]不使用分类器向工件添加源代码,因为Maven只支持每个工件一个分类器。当前工件[com . my company:my project:war:clover:parent project-SNAPSHOT]有一个[clover]分类器。
这是Maven的局限性。它不支持具有多个分类器的项目。由于分叉生命周期中的工件已经具有“三叶草”分类器,因此它不能同时具有“源”分类器。这就是出现此警告的原因。如果您需要调用 maven-source-plugin,您可以考虑使用 clover2:setup 而不是 clover2:instrument。
4. Fork lifecycle for Clover plugin.
--- End forked lifecycle (Clover only forks through 'test' phase).
有两个三叶草目标派生出一个版本:
>
Clover2:仪器-分叉构建,直到“安装”阶段
clover2:仪器测试-将构建分叉到“测试”阶段
你可能对后者感兴趣。您可能还对使用useCloverClassifier=false选项感兴趣-这将在分叉构建中禁用“clover”分类器的使用。
我还发现,当“MyProject-clover.war”由Tomcat7托管时,它没有按预期运行(在浏览器中返回404错误)。
我的第一个猜测是,您在运行时缺少clover . jar(com . atlassian . clover:clover)。您必须将clover.jar复制到Tomcat的/lib目录,或者将其捆绑到您的WAR中。查看https://confluence.atlassian.com/display/CLOVER/Using三叶草的网络应用
如果 Illustrator 崩溃并且您忘记了保存数据,那么可以恢复您的工作。Illustrator 可以帮助您确定崩溃的原因,防止存在问题的项目载入 Illustrator 中,并且可以提供一个引发问题的项目列表,以便您能够解决这些问题。另外,您还可以决定恢复数据的频率以及存储恢复数据的位置。 设置“数据恢复”首选项 设置下列首选项(“首选项”>“文件处理和剪贴板”>“数据恢复”区域): 自动存
我正在编写一个从MQ读取分段消息的使用者。我使用Spring JMS/Spring集成来处理其他队列。我知道IBM MQ不支持JMS中的消息分段:(这里的相关问题:如何在Spring integration中组装MQ消息段) 下面是我想出的将IBM MQ类用于java和Spring的方法。 MQ对象的Bean定义。 消费者代码: 使用这种配置,使用者可以按照需要工作,它将所有分段的消息组装起来,作
我正在尝试构建我的项目,但由于以下错误而失败: "运行命令-失败![错误]运行cordova准备时出错(退出代码1): 我尝试使用以下方法安装cordova插件: > $ionic cordova插件添加cordova插件失眠$npm安装--保存@ionic native/失眠 Cordova插件添加https://github.com/EddyVerbruggen/Insomnia-PhoneG
问题内容: 我有以下代码可以向服务器发出请求: 因此,我需要将返回的数据传递给一个像这样的变量: 在控制台上: 未定义 问题出在哪里,应该在完成后返回数据,但不是。 问题答案: 默认情况下,请求是异步的,因此通常会在请求完成之前返回对的调用。您可以改用回调函数。 如果绝对必要,则可以在中调用。
如何保存已训练的模型? 以后如何还原此保存的模型?
我的项目运行正常。我只是做了一次Lint检查,它给了我所有项目的错误。所以我刚刚清理了我的项目。但现在它并没有生成R.java文件。我怎样才能找回它。我试着建造。。但它不起作用