gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:53:00 25 4
gpt4 key购买 nike

我有这样的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 插件来生成报告请帮助理解问题所在

最佳答案

使用 Jenkins Maven Build 输入目标:mvn clean package

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

对于 surefire encoding 使用的报告编码设置属性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值(value)jar ,因为它是默认的。
  • 删除 sourceDirectory值(value)src/main/java因为它是默认的
  • 删除 outputDirectory机智值target/classes因为它是默认的
  • 删除 testOutputDirectory值(value)target/test-classes因为它是默认的
  • 删除resources/resource/directory值为 src/main/resources因为它是默认的

  • 问题:是 testSourceDirectory真的很值src/test/java/com/my/tests ?看起来它包含包名称的一部分。它应该只包含包名称开始的目录路径。与 sourceDirectory 完全相同,值为 src/main/java 。更合乎逻辑的值是 src/test/java ,这是默认的,所以不需要设置它。

  • 删除 reporting条目,全部是默认的。如果您想更改输出位置,请设置属性 project.reporting.outputDirectory (参见Site Output Directory)

  • 删除 finalName ,因为它变得更不清楚然后更清晰。默认值是 Artifact ID,所以这里 automation .


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

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>
<version>1.0-SNAPSHOT</version>

<build>
<testSourceDirectory>src/test/java/com/my/tests</testSourceDirectory>

<plugins>
<plugin>
<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>
</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>
</configuration>
</plugin>

</plugins>
</build>

<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>

关于java - Maven pom.xml 设置插件编码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33085327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com