简体   繁体   English

gradle to maven插件转换

[英]gradle to maven plugin conversion

How can I write equivalent maven plugin for the following gradle plugin defined? 如何为定义的以下gradle插件编写等效的maven插件?

/*
* Plugin to copy system properties from gradle JVM to testing JVM  
* Code was copied from gradle discussion froum:  
* http://forums.gradle.org/gradle/topics/passing_system_properties_to_test_task
*/  
class SystemPropertiesMappingPlugin implements Plugin{  
    public void apply(Project project){  
        project.tasks.withType(Test){ testTask ->  
            testTask.ext.mappedSystemProperties = []  
            doFirst{  
                mappedSystemProperties.each{mappedPropertyKey ->  
                    def systemPropertyValue = System.getProperty(mappedPropertyKey)  
                    if(systemPropertyValue){  
                        testTask.systemProperty(mappedPropertyKey, systemPropertyValue)  
                    }  
                }  
            }  
        }  
    }  
}

It really depends on what exactly you want to achieve. 这实际上取决于你想要达到的目标。

In case you want to help with writing a maven plugin in general, you'll have to read the documentation . 如果你想帮助编写一般的maven插件,你必须阅读文档

In case you want to filter system properties that Maven JVM passes to your test JVM, I don't see any other option than extending the maven-surefire-plugin plugin and add there an option to do such mapping. 如果你想过滤Maven JVM传递给你的测试JVM的系统属性,我没有看到任何其他选项,除了扩展maven-surefire-plugin插件并添加一个选项来进行这样的映射。 (Note that by default Maven passes all its System Properties to the test JVM.) That is definitely doable but maybe you can achieve your goal with something maven already offers. (请注意,默认情况下,Maven将其所有系统属性传递给测试JVM。)这绝对可行,但也许您可以通过maven已经提供的东西实现您的目标。

You can definitely pass additional system properties to your test JVM from Maven by using: 您可以使用以下方法将其他系统属性从Maven传递到测试JVM:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.19</version>
     <configuration>
         <systemPropertyVariables>
              <propertyName>propertyValue</propertyName>
              <anotherProperty>${myMavenProperty}</buildDirectory>
         </systemPropertyVariables>
     </configuration>
</plugin>

as documented http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html . http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html所述

In this case you can set the value of anotherProperty from command line by invoking maven 在这种情况下,您可以通过调用maven从命令行设置anotherProperty的值

mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty

You can also use Surefire argline to pass multiple properties to the JVM. 您还可以使用Surefire argline将多个属性传递给JVM。 For instance 例如

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.19</version>
     <configuration>
         <argLine>${propertiesIWantToSetFromMvnCommandLine}</argLine>
     </configuration>
</plugin>

and execute maven as follows 并按如下方式执行maven

mvn test -DpropertiesIWantToSetFromMvnCommandLine="-Dfoo=bar -Dhello=ahoy"

in this case, you'll see properties foo and hello with values bar and ahoy , respectively, in your test JVM. 在这种情况下,您将在测试JVM中分别看到值为barahoy属性foohello

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

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