简体   繁体   English

从 pom.xml 外的命令行运行 maven 插件

[英]Running maven plugin from command line outside pom.xml

Below is the snyk plugin setup for maven.下面是 maven 的 snyk 插件设置。 I have setup the plugin in pom.xml.我已经在 pom.xml 中设置了插件。 I configured the maven set up in a pipeline.我配置了在管道中设置的 maven。 The below configuration has a secret API_TOKEN.以下配置有一个秘密 API_TOKEN。 Setting API_TOKEN as a variable in any file except the default pipeline file does not work.将 API_TOKEN 设置为除默认管道文件之外的任何文件中的变量都不起作用。 So I am exploring some way to setup and run the plugin in pipeline file ie to access and run plugin in mvn commandline for example mvn my-plugin:my-goal -Dplugin.property=ABC.所以我正在探索一些在管道文件中设置和运行插件的方法,即在 mvn 命令行中访问和运行插件,例如 mvn my-plugin:my-goal -Dplugin.property=ABC。

But I am not sure, how to call snyk plugin and run during build/install/deploy command.但我不确定如何调用 snyk 插件并在构建/安装/部署命令期间运行。

<plugin>
                <groupId>io.snyk</groupId>
                <artifactId>snyk-maven-plugin</artifactId>
                <version>1.2.5</version>
                <executions>
                    <execution>
                        <id>snyk-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>snyk-monitor</id>
                        <phase>install</phase>
                        <goals>
                            <goal>monitor</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <apiToken>${SNYK_TOKEN}</apiToken>
                    <failOnSeverity>high</failOnSeverity>
                    <org>MDA</org>
                </configuration>
            </plugin>

The team just released a new version of the plugin.该团队刚刚发布了该插件的新版本。 This is the github repo .这是github 存储库

Example例子

<build>
  <plugins>
    <plugin>
      <groupId>io.snyk</groupId>
      <artifactId>snyk-maven-plugin</artifactId>
      <version>2.0.0</version>
      <inherited>false</inherited>
      <executions>
        <execution>
          <id>snyk-test</id>
          <goals>
            <goal>test</goal>
          </goals>
        </execution>
        <execution>
          <id>snyk-monitor</id>
          <goals>
            <goal>monitor</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <apiToken>${env.SNYK_TOKEN}</apiToken>
        <args>
          <arg>--all-projects</arg>
        </args>
      </configuration>
    </plugin>
  </plugins>
</build>

By default now the snyk-test is linked to the mvn test .默认情况下,现在snyk-test链接到mvn test The monitor is connected to the mvn install phase by default. monitor默认连接到mvn install阶段。 Obviously, you can change this like below.显然,您可以像下面这样更改它。

<executions>
   <execution>
       <phase>verify</phase>
       <id>snyk-test</id>
       <goals>
           <goal>test</goal>
       </goals>
   </execution>
   <execution>
       <phase>none</phase>
       <id>snyk-monitor</id>
       <goals>
           <goal>monitor</goal>
       </goals>
   </execution>
</executions>

The API token in the first example is referring to an environment variable.第一个示例中的 API 令牌指的是环境变量。

For more information maybe this blog post gives a more complete overview.有关更多信息,这篇博客文章可能会提供更完整的概述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM