Maven profiles and install

11,351

Well, you could use the classifier attribute so that each profile creates a jar with the classifier, i.e. a unique jar for each environment. Here is a code snippet to illustrate this. When run with the dev profile (mvn -P dev install), it creates a jar with -dev classifier, like myapp-dev-0.0.1.jar

<project>
...
    <properties>
        <env></env>
    </properties>
...

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <classifier>${env}</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <profiles>
        ...
        <profile>
            <id>dev</id>
            <properties>
                <env>dev</env>
            </properties>
            ...
        </profile>
    </profiles>

</project>
Share:
11,351
brabster
Author by

brabster

I'm brabster on twitter. My qualifications: SCJP 5 (2008) SCWCD 5 (2009) MSc. Advance Computer Science (2013) I've been following the progress of stackoverflow with interest from the beginning, proud to have been involved with the beta test.

Updated on July 28, 2022

Comments

  • brabster
    brabster almost 2 years

    If I have Maven builds set up for an app with profiles set up for different environments (say like prod vs. dev, defining different DB settings and stuff like that) the 'install' goal doesn't seem to make sense, as I don't know which environment got installed into my repo - I've just got com.example.myproject:myapp:0.0.1.

    Have I misunderstood something, or are profiles supposed to be used with other goals?