Program Club

Maven이 인코딩에 대해 경고하는 이유는 무엇입니까?

proclub 2020. 11. 7. 10:40
반응형

Maven이 인코딩에 대해 경고하는 이유는 무엇입니까?


내 목표는 프로젝트에서 원형을 만드는 것입니다.

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

"표준"메이븐 방법은 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>


goal을 실행할 때 archetype:create-from-projectMaven은 아키타 입을 빌드하기위한 POM 파일을 생성 한 target/generated-sources/archetype/pom.xml다음 package이 POM 에서 목표 (기본적으로) 를 실행합니다 .

생성 된 POM 파일에는 project.build.sourceEncoding인코딩을 정의하는 기타 속성 이 없으므로 경고가 표시됩니다.

The POM is generated from this prototype by org.apache.maven.archetype.creator.FilesetArchetypeCreator#createArchetypeProjectPom, and from that code there doesn't seem to be a way to add properties to the resulting POM file.


You haven't set the encoding default property like this:

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

This approach is better than defining encoding manually for every plugin, cause all plugins having default values for 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}

So this means you only need to define this property and the plugin will automatically use this encoding.


I was annoyed to see that maven kept on complaining after the above entry

Then I realized that its the failsafe plugin and it needs its own property

So here it goes

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

참고URL : https://stackoverflow.com/questions/24144073/why-does-maven-warn-me-about-encoding

반응형