Mi piacerebbe usare proprietà-maven-plugin. Leggo l'utilizzo http://mojohaus.org/properties-maven-plugin/usage.html, ma non funziona per me.Come usare proprietà-maven-plugin?
Ho creato un progetto molto semplice per testarlo. Ecco la mia pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>MavenTest</artifactId>
<version>1.0.0</version>
<name>MavenTest</name>
<properties>
<prop1>2.2</prop1>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/my.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
properties-maven-plugin
</artifactId>
<versionRange>
[1.0-alpha-2,)
</versionRange>
<goals>
<goal>
read-project-properties
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
se corro mvn compilo, o mvn installare il risultato è:
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for org.apache.logging.log4j:log4j-api:jar must be a valid version but is '${log4j.version}'. @ line 16, column 13
Il file "my.properties" contiene questo:
log4j.version=2.2
Come descritto qui: mojohaus
Se uso la proprietà prop1, che è definita nel pom.xml, tutto s funziona.
Quindi cosa sto facendo male?
Hai messo il file nella directory corretta? Significa che non si ricevono errori o avvisi all'avvio di build di maven? –
Sì, l'ho fatto. La vista pom efficace di Eclipse mostra il percorso corretto (assoluto) del file. E ho ricevuto solo quell'errore, che è mostrato nella domanda – zsom
senza risoluzione per questa domanda? Sto avendo lo stesso problema .. – AlexGreg