Maven pom.xml为插件设置编码不起作用

时间:2015-10-12 15:54:33

标签: java xml maven maven-surefire-plugin

我有这样的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.my</groupId>
    <artifactId>automation</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <build>
        <directory>target</directory>
        <sourceDirectory>src/main/java</sourceDirectory>
        <outputDirectory>target/classes</outputDirectory>
        <finalName>AUTOMATION-01</finalName>
        <testSourceDirectory>src/test/java/com/my/tests</testSourceDirectory>
        <testOutputDirectory>target/test-classes</testOutputDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>

                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <updateReleaseInfo>true</updateReleaseInfo>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>10</threadCount>
                    <groups>com.my.testgroups.AutoTestsGroup</groups>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>

        </plugins>
    </build>


    <reporting>
        <outputDirectory>target/site</outputDirectory>
    </reporting>

    <profiles>

        <profile>
            <id>release-profile</id>
            <activation>
                <property>
                    <name>performRelease</name>
                </property>
            </activation>
        </profile>
    </profiles>


    <dependencies>
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.12</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

</project>

我使用maven-surefire-plugin通过报告

生成报告
 Получаем имя файла с тесткейсом и имя самого тесткейса
2015-10-12 11:30:57 INFO  - Выполняется файл тесткейс : case1_125_multidrive, с именем кейса: Собственник_равно_Страхователь_Москва-возраст_больше_18-125лс_мультидрайв
2015-10-12 11:30:57 INFO  - ########## Создаем владельца ТС #########
2015-10-12 11:30:57 INFO  - Фамилия Витряк
2015-10-12 11:30:57 INFO  - �мя Агап
2015-10-12 11:30:57 INFO  - Отчество Алексеевич
2015-10-12 11:30:57 INFO  - Генерируем дату рождения в соответствии с условием: возраст_больше_18
2015-10-12 11:30:57 INFO  - Дата рождения: 1967-01-16
2015-10-12 11:30:57 INFO  - Водительский стаж не будет сгенерирован, мультидрайв
2015-10-12 11:30:57 INFO  - ######### Starting create user request on UAT env. ########
2015-10-12 11:30:57 INFO  - Создан владелец ТС с publicID: su:2086
2015-10-12 11:30:59 INFO  - Каско квота стоимость null
2015-10-12 11:30:59 INFO  - Осаго квота стоимость null

我确实为这个插件设置了编码,但它根本不起作用。 我尝试在Jenkins上运行maven并使用JUnit Jenkins插件进行报告 请帮助理解问题是什么

2 个答案:

答案 0 :(得分:1)

使用Jenkins Maven Build 输入目标:O(k)

使用Jenkins M2 Release Plugin 创建新版本的库。这会将创建jar部署到中央Maven存储库,如NexusArtifactory

对于surefire encoding使用的报告编码,请设置属性mvn clean package

project.reporting.outputEncoding

<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> 中有几件可以删除的内容,因为它们是pom.xml默认值。像:

  • 删除值为pom.xml的条目packaging,因为它是默认值。
  • 删除值为jar的{​​{1}},因为它是默认值
  • 删除sourceDirectory机智值src/main/java,因为它是默认值
  • 删除值为outputDirectory的{​​{1}},因为它是默认值
  • 删除target/classes,其值为testOutputDirectory,因为它是默认值

  • 问题:target/test-classes值真的是resources/resource/directory吗?看起来它包含了包名称的一部分。它应该只包含pacakge名称开始的目录的路径。与src/main/resources完全相同,值为testSourceDirectory。更合乎逻辑的值是src/test/java/com/my/tests,这是默认值,因此不需要设置它。

  • 删除sourceDirectory条目,均为默认值。如果您想更改输出位置,请设置属性src/main/java(请参阅Site Output Directory

  • 删除src/test/java,因为更清楚,更清楚。默认值为工件ID,因此reporting

project.reporting.outputDirectory

finalName可能如下所示:

automation

答案 1 :(得分:0)

尝试:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-site-plugin</artifactId>
    <version>3.2</version>
    <configuration>
      <outputEncoding>UTF-8</outputEncoding>
    </configuration>
  </plugin>

并且:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>