gpt4 book ai didi

java - 为什么 Maven 会警告我有关编码的问题?

转载 作者:IT老高 更新时间:2023-10-28 13:51:53 24 4
gpt4 key购买 nike

我的目标是从项目中创建原型(prototype)。

当我运行一个不涉及 maven-archetype-plugin 的目标时,我看不到任何警告:

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-archetype-base ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-archetype-base ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]

另一方面,当我运行 archetype:create-from-project 时,我得到了一对:

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-archetype-base-archetype ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-archetype-base-archetype ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources

我知道“标准”的 maven 方式是使用 project.build.sourceEncoding 属性。我尝试向 pom 添加更多属性以解决此问题,但它们都不起作用。

有什么想法吗?谢谢。

我有以下 pom.xml:

<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>my.group.id</groupId>
<artifactId>my-artifact</artifactId>
<version>0.0.1</version>
<packaging>maven-archetype</packaging>

<properties>

<!-- Compiler properties -->
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
<project.resources.sourceEncoding>${encoding}</project.resources.sourceEncoding>
<archetype.encoding>${encoding}</archetype.encoding>

<!-- Maven plugins version -->
<maven-archetype-plugin-version>2.2</maven-archetype-plugin-version>
<maven-resources-plugin-version>2.6</maven-resources-plugin-version>

<!-- Maven extentions version -->
<maven-archetype-packaging-extension-version>2.2</maven-archetype-packaging-extension-version>
</properties>
<dependencies>
[...]
</dependencies>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>${maven-archetype-packaging-extension-version}</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>${maven-archetype-plugin-version}</version>
<extensions>true</extensions>
</plugin>

</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

最佳答案

您还没有设置encoding default像这样的属性:

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

这种方法比为每个插件手动定义编码要好,因为所有插件都有 encoding for example the maven-resources-plugin 的默认值:

encoding:

The character encoding scheme to be applied when filtering resources.
Type: java.lang.String
Required: No
User Property: encoding
Default: ${project.build.sourceEncoding}

所以这意味着你只需要定义这个属性,插件就会自动使用这个编码。

关于java - 为什么 Maven 会警告我有关编码的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24144073/

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