鉴于Jacoco在"动态"工具时不能很好地与PowerMockito配合使用,我一直在尝试配置离线工具,希望这能为我提供适用于使用PowerMockito的类的单元测试覆盖率.
我已经将我的pom设置如下,但我的测试课程仍然保持0%的覆盖率.任何帮助都非常感激,因为它让我慢慢疯狂!
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mandy</groupId>
<artifactId>jacoco-test</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>jacoco-test Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<powermock.version>1.5.4</powermock.version>
<jacoco.version>0.7.1.201405082137</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>instrument</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-report</id>
<phase>prepare-package</phase>
<goals>
<goal>restore-instrumented-classes</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin> …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个包含xml文件作为资源的jar.我想对该xml应用过滤器以将依赖项的名称插入到xml中.过滤是有效的,因为我能够进入${project.build.finalName}并取代它.我发现了一个暗示,我正在寻找的房产可能是
${project.dependencies[0].artifactId}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.我想替换
<fileName>${project.dependencies[0].artifactId}</fileName>
Run Code Online (Sandbox Code Playgroud)
同
<fileName>OtherLibrary</fileName>
Run Code Online (Sandbox Code Playgroud)
那可能吗?
xml,位于src/main/resources中:
<somenode>
<fileName>${project.dependencies[0].artifactId}</fileName>
</somenode>
Run Code Online (Sandbox Code Playgroud)
pom.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>Thing</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Thing</name>
<url>http://maven.apache.org</url>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.pts</groupId>
<artifactId>OtherLibrary</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud) 在Maven项目中,我的一个直接依赖项具有间接依赖性com.foo:bar.我需要的是Maven属性(例如${bar-version}),其中包含此工件的版本号.我需要这个机制来处理几个间接依赖的版本号.
我从那个问题中学到了我可以${maven.dependency.com.foo.bar.jar.path}在antrun插件中访问工件jar的本地路径.我现在使用的解决方法是/path/to/repository/com/foo/bar/2.1.1/bar-2.1.1.jar在antrun执行中解析它的值(例如)并在那里定义一个属性(配置exportAntProperties是我的朋友).但是,由于默认情况下ant没有良好的字符串正则表达式操作,这非常麻烦.
还有其他${maven.dependency.com.foo.bar.jar.path}可用的房产吗?我试过了${maven.dependency.com.foo.bar.jar.version},但没办法.我还想了解这个属性背后的机制.它是由Java类支持的吗?就像project.organization.name 是getProject().getOrganizarion().getName()在相应的Maven类...
欢迎任何帮助!
谢谢,约翰内斯
给定一个简单的Maven项目,例如JUnit作为依赖项,如何将完整的文件路径放到junit.jar它将安装到的本地maven存储库中?
例如如何从神器junit:junit到/Users/foobar/.m2/repository/junit/junit/4.11/junit-4.11.jar?
java ×3
dependencies ×2
maven ×2
ant ×1
filtering ×1
jacoco ×1
maven-2 ×1
powermock ×1
properties ×1
resources ×1