Why does Maven warn me about coding?

My goal is to create an archetype from a project.

When I run a target that does not include the maven-archetype plugin, I do not 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 hand, when I run the 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, ie 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, ie build is platform dependent! [INFO] Copying 2 resources 

I know that the "standard" way of maven is to use the project.build.sourceEncoding property. I tried adding a few more properties for pom to solve this problem, but none of them worked.

Any ideas? Thank.

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> 

+46
java maven maven-archetype
Jun 10 '14 at 14:50
source share
4 answers

When you run the archetype:create-from-project target/generated-sources/archetype/pom.xml , Maven creates a POM file to create an archetype in target/generated-sources/archetype/pom.xml , and then runs the package target (by default) on that POM.

The generated POM file does not have project.build.sourceEncoding or any other property that defines the encoding, and why you get a warning.

POM is generated from this prototype org.apache.maven.archetype.creator.FilesetArchetypeCreator#createArchetypeProjectPom , and from this code there isn’t β€œt seems to be a way to add properties to the resulting POM file.

+13
Jun 11 '14 at 11:02
source share

You did not set the encoding default property as follows:

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

This approach is better than defining the encoding manually for each plugin, because all plugins have default encoding values , for example, 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 that you only need to define this property, and the plugin will automatically use this encoding.

+67
Jun 10 '14 at 15:00
source share

I was annoyed to see maven keep complaining after the above post

Then I realized that it is a protected plugin and it needs its own property

So here it is

 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties 
+7
Oct 06 '16 at 20:55
source share

To remove this warning, if you really do not want the build to be platform dependent, you must specify the source encoding for the platform-independent build in your Maven project by following these steps:

  • Open the pom file.
  • Add the following code:

     <project> ... <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> ... </project> 
  • Run the following command:

mvn package

  1. Please note that the warning is no longer present.

How it works

The project.build.sourceEncoding property explicitly indicates the encoding of the source files. Maven plugins get encoding information from the value of this property and use it. This value will be the same on any platform on which the project is built, and thus the assembly becomes independent of the platform.

+6
Nov 25 '15 at 16:03
source share



All Articles