如何在 Maven 中启动单个目标/执行

Mar*_*tin 2 maven-3

目前我正在调试 Android 应用程序的签名。如果我可以只执行这个插件,这会容易得多:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jarsigner-plugin</artifactId>
  <executions>
    <execution>
      <id>signing</id>
      <goals>
        <goal>sign</goal>
      </goals>
      <phase>package</phase>
Run Code Online (Sandbox Code Playgroud)

但无论我尝试什么,我得到的都是:

[ERROR] Could not find goal 'signing' in plugin org.apache.maven.plugins:maven-jarsigner-plugin:1.2 among available goals verify, sign, help -> [Help 1]
org.apache.maven.plugin.MojoNotFoundException: Could not find goal 'signing' in plugin org.apache.maven.plugins:maven-jarsigner-plugin:1.2 among available goals verify,
 sign, help
Run Code Online (Sandbox Code Playgroud)

或者

org.apache.maven.lifecycle.LifecyclePhaseNotFoundException: Unknown lifecycle phase "sign". You must specify a valid lifecycle phase or a goal in the format <plugin-pre
fix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources
, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-co
mpile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, p
ost-clean, pre-site, site, post-site, site-deploy.
Run Code Online (Sandbox Code Playgroud)

或其他一些错误。

Ben*_*nus 5

您可以使用以下命令仅运行 sign 目标:

mvn jarsigner:sign
Run Code Online (Sandbox Code Playgroud)

我有这个插件配置是我的pom是这样的:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <version>1.2</version>
    <executions>
        <execution>
            <id>signer</id>
            <goals>
                <goal>sign</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <archive>target/${project.artifactId}-${project.version}.jar</archive>
        <keystore>src/main/signer/.keystore</keystore>
        <alias>MyCert</alias>
        <storepass>password</storepass>
        <keypass>password</keypass>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

因为我已经<archive>指向目标目录中的一个工件,所以我必须先运行一个mvn clean install,然后mvn jarsigner:sign如果我想再次运行 maven-jarsigner-plugin 来对 jar 进行签名,我就可以执行。(我通常不会只运行这个插件/目标,因为我一直在做一个完整的“mvn clean install”,但它确实有效。)