How do I define a compile-time *only* classpath in Gradle?

前端 未结 11 2162
[愿得一人]
[愿得一人] 2020-12-02 11:51

Can someone please give me a simple build.gradle example of how I can specify compile-time-only classes that are not included in the runtime deployment (war).

Gradl

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 12:41

    There has been a lot of discussion regarding this topic, mainly here, but not clear conclusion.

    You are on the right track: currently the best solution is to declare your own provided configuration, that will included compile-only dependencies and add to to your compile classpath:

    configurations{
      provided
    }
    
    dependencies{
      //Add libraries like lombok, findbugs etc
      provided '...'
    }
    
    //Include provided for compilation
    sourceSets.main.compileClasspath += [configurations.provided]
    
    // optional: if using 'idea' plugin
    idea {
      module{
        scopes.PROVIDED.plus += [configurations.provided]
      }
    }
    
    // optional: if using 'eclipse' plugin
    eclipse {
      classpath {
        plusConfigurations += [configurations.provided]
      }
    }
    

    Typically this works well.

提交回复
热议问题