Exclude dependency in a profile

后端 未结 6 2013
别那么骄傲
别那么骄傲 2021-02-06 23:49

I have a maven module which has some dependencies. In a certain profile, I want to exclude some of those dependencies (to be exact, all dependencies with a certain group id). Th

6条回答
  •  眼角桃花
    2021-02-07 00:48

    maven is a tool, we can hack it.

    • maven runs fine if you have the same artifact + version defined as dependency twice.
    • define a profile that eliminates an artifact + version by changing it to another package we already have.

    For example, in the pom.xml:

    ... other pom stuff ...
      
        artifact1
        artifact2
        0.4
        0.5
      
    
      
        remove-artifact2
        
          artifact1
          artifact1
          0.4
          0.4
        
      
    
    • Now if you install this pom.xml without the profile, artifact1:0.4 and artifact2:0.5 will be the dependency.
    • But if you install this pom.xml with the profile mvn -P remove-artifact2 The result pom.xml contains only artifact1:0.4

    This comes quite handy during api migration where artifact are renamed and versions are not compatible.

提交回复
热议问题