Required Java version of Maven Dependency?

前端 未结 2 1680
日久生厌
日久生厌 2020-12-08 07:49

I developed and built my Java application using Maven. I need to support Java 1.6, so I use the following properties:

1.6         


        
2条回答
  •  抹茶落季
    2020-12-08 08:28

    The problem is that every dependency (maintainer) can decide on it's own which java version is used to compile (1.5, 1.6, 1.7, 1.8 etc) so this is not solvable via Maven. But you can make sure that you don't use dependencies which are using a different Java version than you like to have.

    This can be enfored by using Maven Enforcer Plugin by using extra-enforcer-rules:

    
      [...]
      
        
          
            org.apache.maven.plugins
            maven-enforcer-plugin
            1.4.1 
            
              
                enforce-bytecode-version
                
                  enforce
                
                
                  
                    
                      1.6
                      
                        org.mindrot:jbcrypt
                      
                    
                  
                  true
                
              
            
            
              
                org.codehaus.mojo
                extra-enforcer-rules
                1.0-beta-5
              
            
          
        
      
      [...]
    
    

    This will break your build if you have a dependency which is compiled with a different version of JDK than you want to have.

提交回复
热议问题