简体   繁体   中英

Use variables from properties file in a Maven Plugin

I need to be able to use "variables" for a maven plugin like this:

                <plugin>
                    <groupId>com.jelastic</groupId>
                    <artifactId>jelastic-maven-plugin</artifactId>
                    <version>1.8.4</version>
                    <configuration>
                        <api_hoster>${api_hoster}</api_hoster>
                        <email>${email}</email>
                        <password>${password}</password>
                        <environment>${environment}</environment>
                        <!--<context>[specify the context if you need it]</context>-->
                        <!--<comment>[insert comment if you need it]</comment>-->
                    </configuration>
                </plugin>

Already have the properties file set in the base directory and have used the plugin:

                <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}/jelastic.properties</file>
                                </files>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Still, the variables in the plugin cannot be resolved, what could be wrong here?

You must either declare those variables as <properties> in project or profile or pass them as env variables like mvn whatever -Dyourprop=value

Read about properties: https://maven.apache.org/pom.html#Properties

Read about profiles: https://maven.apache.org/guides/introduction/introduction-to-profiles.html

add those lines to your POM:

    <build>
    <resources>
    <resource>
    <includes>
    <include>**/*.properties</include>
    </includes>
    <directory>src/main/resources</directory>
    </resource>
    </resources>
    </build>

And this properties file:

   api_hoster:${api_hoster}
   email:${email}
   password:${password}
   environment:${environment}

and invoke any maven plugin by mentioning a profile:

mvn clean -Pname

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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