草庐IT

java - Maven:从命令行执行并在配置中多次执行

coder 2024-03-30 原文

我想从命令行执行插件目标,但要执行插件的多次执行。为此,我的 POM 如下所示:

<plugin>
    <groupId>xxx.yyy</groupId>
    <artifactId>zzz</artifactId>
    <version>1.1.6</version>
    <executions>
        <execution>
            <id>default-cli-1</id>
            <goals>
                <goal>mygoal</goal>
            </goals>
            <configuration>
                .... config1 ....
            </configuration>
        </execution>
        <execution>
            <id>default-cli-2</id>
            <goals>
                <goal>mygoal</goal>
            </goals>
            <configuration>
                .... config2 ....
            </configuration>
        </execution>
    </executions>
</plugin>

我想做的是:

mvn xxx.yyy.zzz:mygoal

然后这将执行两次执行。但我想不通。

我知道我不能使用 <id>从命令行执行时。那就是default-cli是为了。然而 <id><executions> 中必须是唯一的这意味着我只能把 default-cli在一个execution .

Maven 版本3.0.5

最佳答案

从 Maven 3.3.1this 开始,您可以从命令行执行目标(及其执行)新功能,通过 @executionId 附加选项。

关于Maven和execution ids的生成,你也可以查看this SO question .


在 Maven 3.3.1 之前,您可以改为将这两个执行绑定(bind)到一个通常不会造成伤害的阶段(如 validate),并具有如下内容:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
            <id>execution-1</id>
            <phase>validate</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>something1</classifier>
            </configuration>
        </execution>
        <execution>
            <id>execution-2</id>
            <phase>validate</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>something2</classifier>
            </configuration>
        </execution>
    </executions>
</plugin>

然后执行:

mvn validate

作为无害阶段的一部分,您将有效地执行同一插件的同一目标的两次执行。

如果您不希望默认情况下将它们作为此阶段的一部分(可以理解),那么您可以将它们移动到一个配置文件中并将其激活为执行的一部分:

mvn validate -PpluginGoalExecution

为了完整起见,配置文件如下所示:

<profile>
    <id>pluginExecution</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <id>execution1</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>something1</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>execution2</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>something2</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

不言而喻:在这种情况下,配置文件的 id 应该非常清楚地说明它实际执行的是哪个插件和哪个目标(即,像往常一样,配置文件的目的)。

更新
只是装饰性的,但您也可以添加到元素上方的配置文件中:

<defaultGoal>validate</defaultGoal>

因此您只需要运行以下 Maven 命令(仅配置文件激活):

mvn -PpluginGoalExecution

然后它会自动执行验证阶段和配置的插件执行。变化不大(正如我所说,是表面上的),但可能更接近于插件目标执行而不是 Maven 阶段调用(同样,只是外观)。

关于java - Maven:从命令行执行并在配置中多次执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34902978/

有关java - Maven:从命令行执行并在配置中多次执行的更多相关文章

  1. ruby-openid:执行发现时未设置@socket - 2

    我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass

  2. ruby - 多次弹出/移动 ruby​​ 数组 - 2

    我的代码目前看起来像这样numbers=[1,2,3,4,5]defpop_threepop=[]3.times{pop有没有办法在一行中完成pop_three方法中的内容?我基本上想做类似numbers.slice(0,3)的事情,但要删除切片中的数组项。嗯...嗯,我想我刚刚意识到我可以试试slice! 最佳答案 是numbers.pop(3)或者numbers.shift(3)如果你想要另一边。 关于ruby-多次弹出/移动ruby​​数组,我们在StackOverflow上找到一

  3. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  4. ruby - Chef 执行非顺序配方 - 2

    我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul

  5. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  6. ruby - 为什么 Ruby 的 each 迭代器先执行? - 2

    我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试

  7. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  8. java - 我的模型类或其他类中应该有逻辑吗 - 2

    我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我

  9. ruby - 检查是否通过 require 执行或导入了 Ruby 程序 - 2

    如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby​​文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否

  10. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

随机推荐