Maven profiles and install

南笙酒味 提交于 2019-12-12 10:08:56

问题


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?


回答1:


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>



回答2:


You run the usual mvn commands and can select the appropriate profile with -P http://maven.apache.org/guides/introduction/introduction-to-profiles.html So it dependends on which profile you chose, what gets installed in the repository.



来源:https://stackoverflow.com/questions/4656946/maven-profiles-and-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!