参数 'sourceEncoding' rpm-maven-plugin 丢失或无效

The parameters 'sourceEncoding' rpm-maven-plugin are missing or invalid

我正在尝试使用 rpm maven 插件,但出现以下错误:

[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.3:rpm (generate-rpm) on project TestRpmAndDocker: The parameters 'sourceEncoding' for goal org.codehaus.mojo:rpm-maven-plugin:2.1.3:rpm are missing or invalid -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.1.3:rpm (generate-rpm) on project TestRpmAndDocker: The parameters 'sourceEncoding' for goal org.codehaus.mojo:rpm-maven-plugin:2.1.3:rpm are missing or invalid at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:220) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213) at org.apache.maven.cli.MavenCli.main(MavenCli.java:157) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'sourceEncoding' for goal org.codehaus.mojo:rpm-maven-plugin:2.1.3:rpm are missing or invalid at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:584) at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:537) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:120) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 19 more

这是我的 pom:

<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>TestRpmAndDocker</groupId>
<artifactId>TestRpmAndDocker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>TestRpmAndDocker</name>
<description>TestRpmAndDocker</description>


<build>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>rpm-maven-plugin</artifactId>
            <version>2.1.3</version>
            <executions>
                <execution>
                    <id>generate-rpm</id>
                    <goals>
                        <goal>rpm</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <license>GPL (c) 2005, SWWDC</license>
                <distribution>Trash 2005</distribution>
                <group>Application/Collectors</group>
                <icon>src/main/resources/icon.gif</icon>
                <packager>SWWDC</packager>
                <prefix>/usr/local</prefix>
                <changelogFile>src/changelog</changelogFile>
                <defineStatements>
                    <defineStatement>_unpackaged_files_terminate_build 0</defineStatement>
                </defineStatements>
                <mappings>
                    <mapping>
                        <directory>/usr/local/bin/landfill</directory>
                        <filemode>440</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                        <sources>
                            <source>
                                <location>target/classes</location>
                            </source>
                        </sources>
                    </mapping>
                    <mapping>
                        <directory>/usr/local/doc/landfill</directory>
                        <documentation>true</documentation>
                        <filemode>444</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                        <sources>
                            <source>
                                <location>target/site</location>
                            </source>
                        </sources>
                    </mapping>
                    <mapping>
                        <directory>/usr/local/lib</directory>
                        <filemode>750</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                        <dependency>
                            <includes>
                                <include>jmock:jmock</include>
                                <include>javax.servlet:servlet-api:2.4</include>
                            </includes>
                            <excludes>
                                <exclude>junit:junit</exclude>
                            </excludes>
                        </dependency>
                    </mapping>
                    <mapping>
                        <directory>/usr/local/bin</directory>
                        <filemode>750</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                        <sources>
                            <source>
                                <location>src/main/bin</location>
                            </source>
                            <softlinkSource>
                                <location>/usr/local/bin/new.sh</location>
                                <destination>old.sh</destination>
                            </softlinkSource>
                        </sources>
                    </mapping>
                    <mapping>
                        <directory>/usr/local/oldbin</directory>
                        <filemode>750</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                        <sources>
                            <softlinkSource>
                                <location>/usr/local/bin</location>
                            </softlinkSource>
                        </sources>
                    </mapping>
                    <mapping>
                        <directory>/usr/local/conf/landfill</directory>
                        <configuration>true</configuration>
                        <filemode>640</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                        <sources>
                            <source>
                                <location>src/main/conf</location>
                            </source>
                        </sources>
                    </mapping>
                    <mapping>
                        <directory>/usr/local/log/landfill</directory>
                        <filemode>750</filemode>
                        <username>dumper</username>
                        <groupname>dumpgroup</groupname>
                    </mapping>
                </mappings>
                <preinstallScriptlet>
                    <script>echo "installing now"</script>
                </preinstallScriptlet>
                <postinstallScriptlet>
                    <scriptFile>src/main/scripts/postinstall</scriptFile>
                    <fileEncoding>utf-8</fileEncoding>
                </postinstallScriptlet>

            </configuration>
        </plugin>
    </plugins>
</build>

我想您遗漏了以下 XML 片段。我建议你把它放在 <build> 标签之前。

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

请将此更改为您使用的编码。

另一种方法似乎是您可以将源编码添加到插件配置中,这对我来说比据我所知应该用作变量的属性更有意义。我不明白的是为什么没有记录。显然也需要“rpm”,尽管据我所知这破坏了以前的版本:RPM package using maven

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>rpm-maven-plugin</artifactId>
            <version>2.2.0</version>
            <extensions>true</extensions>
            <configuration>
                <sourceEncoding>UTF-8</sourceEncoding>
            </configuration>
        </plugin>
    </plugins>
</build>