Exclude dependency in a profile

后端 未结 6 1847
别那么骄傲
别那么骄傲 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:38

    I don't think it is possible to exclude direct dependencies either (at least, nothing is mentioned here).

    The best thing you can do is to enclose the desired dependencies for each case into different profiles (as suggested already), but, you'll need to create two "mutually exclusive" profiles with the one of them "active by default". The most reliable way to achieve this is by using a parameter for your profile activation e.g.

    
      
        default-profile
        
          !exclude
        
        
          dependency-A
          dependency-B
          ...
        
      
    
      
        exclude-profile
        
          exclude
        
        
      
     
    

    Then using "mvn [goal]" will use profile "default-profile", but "mvn [goal] -Dexclude" will use profile "exclude-profile".

    Note that using 'activeByDefault' instead of a parameter for your "default" profile might work in some cases but it also might lead to unexpected behavior. The problem is that 'activeByDefault' makes a profile active as long as there is no other active profile in any other module of a multi-module build.

提交回复
热议问题