Problem:
Can Maven's pom.xml file contain different sets of dependencies for different build profiles?
Solution:
Yes, it is possible to specify different dependencies for different profiles in Maven.
According to the Maven documentation, "a profile element contains both an optional activation (a profile trigger) and the set of changes to be made to the POM if that profile has been activated." This allows for customization of the build process based on different scenarios, such as a test environment requiring a different database or different dependencies for different JDK versions.
To achieve this, simply place the dependency for the desired profile within its corresponding profile declaration. For example:
<code class="xml"><profiles> <profile> <id>debug</id> ... <dependencies> <dependency>...</dependency> </dependencies> ... </profile> <profile> <id>release</id> ... <dependencies> <dependency>...</dependency> </dependencies> ... </profile> </profiles></code>
The above is the detailed content of Can Maven's pom.xml file have different dependencies for different build profiles?. For more information, please follow other related articles on the PHP Chinese website!