how to set maven source plugin output file encoding

911 Views Asked by At

using maven source plugin and upload source jar file successfully. while download maven sources from another computer and found source file chinese words messy.here is my build configuration in pom.xml:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.1.2</version>
    <configuration><encoding>UTF-8</encoding>UTF-8<charset></charset></configuration>
    <executions>
    <execution>
<id>attach-sources></id>
<phase>jar</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
    </executions>
    </plugin>
2

There are 2 best solutions below

3
Anshul Sharma On

you can use <encoding>UTF-8</encoding> with maven-resources-plugin 3.0.2 plugin, you can find code belop:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <configuration>
          ...
          <encoding>UTF-8</encoding>
          ...
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

and if you are using Maven 3.x then you useadd below code

<project>
  ...
  <build>

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

and Maven 2.x, use below property:

<project>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    ...
  </properties>
  ...
</project>
0
khmarbaise On

The only solution which is valid is this one:

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

This solution is not related to Maven version (apart from that Maven 2 is end of life)..

This will set this property which is picked up by all apache maven plugins (maven-compiler-plugin,maven-resources-plugin etc.) which includes maven-sources-plugin. But you should use most recent versions of the plugin and not such ancient version.