2015-10-28 12 views
5

Come posso scrivere un plug-in maven equivalente per il seguente plugin gradle definito?conversione da gradle a maven plug-in

/* 
* 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

si desidera convertire il plugin java in Maven giusto? –

+0

Sì ... che posso usare in Maven Pom come plugin. –

+0

Okz prova http://crunchify.com/how-to-convert-existing-java-project-to-maven-in-eclipse/ se mi sbaglio per favore correggimi con spiegami come vuoi farlo imean in quale ide si vuole fare questo –

risposta

1

Dipende davvero da cosa esattamente si vuole raggiungere.

Nel caso in cui si desideri aiutare con la scrittura di un plug-in Maven in generale, è necessario read the documentation.

Nel caso in cui si desideri filtrare le proprietà di sistema che Maven JVM passa alla JVM di test, non vedo altra opzione che estendere il plug-in maven-surefire-plugin e aggiungere lì un'opzione per eseguire tale mappatura. (Nota che di default Maven passa tutte le sue Proprietà di sistema alla JVM di test.) Questo è sicuramente fattibile ma forse puoi raggiungere il tuo obiettivo con qualcosa che Maven già offre.

Si può sicuramente passare ulteriori Proprietà del sistema per la vostra JVM di prova da Maven usando:

<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> 

come documentato http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html.

In questo caso è possibile impostare il valore di anotherProperty da linea di comando invocando Maven

mvn test -DmyMavenProperty=theValueThatWillBePassedToTheTestJVMAsProperty_anotherProperty 

È inoltre possibile utilizzare infallibile argline passare più oggetti da JVM. Per esempio

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

ed eseguire Maven come segue

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

in questo caso, vedrete le proprietà foo e hello con i valori bar e ahoy, rispettivamente, nella vostra JVM di prova.

+0

Ciao .. Con riferimento alla domanda, ho le seguenti proprietà che devono essere mappate: 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'] .... Quindi, come otterrò il valore della proprietà per un nome di proprietà specifico in pom.xml (come System.getProperty non aiuterà qui)? –

Problemi correlati