javamavenmaven-archetype

Why does Maven warn me about encoding?


My goal is to create an archetype from a project.

When I run a goal that does not involve the maven-archetype-plugin, I can't see any warning:

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

On the other end, when I run archetype:create-from-project, I get a couple:

[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

I know that the "standard" maven way is to use the project.build.sourceEncoding property. I tried adding some more properties to the pom in order to address this issue but none of them worked.

Any ideas? Thanks.

I have the following 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>


Solution

  • When you run the goal archetype:create-from-project, Maven generates a POM file for building the archetype at target/generated-sources/archetype/pom.xml and then runs the package goal (by default) on this POM.

    The generated POM file doesn't have project.build.sourceEncoding or any other property defining encoding, and that's why you get the warning.

    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.