quarks
quarks

Reputation: 35276

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?

Upvotes: 2

Views: 3995

Answers (2)

Khalil M
Khalil M

Reputation: 1858

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

Upvotes: 1

Antoniossss
Antoniossss

Reputation: 32507

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

Upvotes: 1

Related Questions