2015-10-28 56 views
5

如何爲以下定義的gradle插件編寫等價的maven插件?gradle to 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) 
        } 
       } 
      } 
     } 
    } 
} 
+0

你想將java插件轉換爲maven嗎? –

+0

是啊..我可以在maven pom中使用它作爲插件。 –

+0

Okz嘗試http://crunchify.com/how-to-convert-existing-java-project-to-maven-in-eclipse/如果我錯了,請糾正我與解釋我如何做到這一點imean in你想要做的這個IDE –

回答

1

這真的取決於你想要達到的目標。

如果您想幫助編寫一般的maven插件,您需要登錄read the documentation

如果你想過濾Maven JVM傳遞給你的測試JVM的系統屬性,除了擴展maven-surefire-plugin插件並添加一個選項來做這樣的映射外,我沒有看到其他的選擇。 (請注意,默認情況下,Maven會將其所有系統屬性傳遞給測試JVM。)這絕對是可行的,但也許您可以通過maven已經提供的某些東西來實現您的目標。

你絕對可以通過使用經過其他系統屬性從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> 

如記錄http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html

在這種情況下,你可以通過調用行家

mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty 

您還可以使用神火argline到多個屬性傳遞到JVM設置的anotherProperty命令行的值。例如

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

和執行行家如下

mvn test -DpropertiesIWantToSetFromMvnCommandLine="-Dfoo=bar -Dhello=ahoy" 
在這種情況下

,你會看到性能foohello與值分別爲barahoy,在您的測試JVM。

+0

你好..關於這個問題,我有以下需要映射的屬性:mappedSystemProperties = ['jivetests','jive.suite.name','jive.package.base','jive.package.include' ,'jive.package.exclude','jive.testclass.include','jive.testclass.exclude', 'jive.testclass.id.include','jive.testclass.id.exclude'] ....那麼如何獲得pom.xml中特定屬性名稱的屬性值(因爲System.getProperty在這裏不起作用)? –