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

前端 未结 11 2175
[愿得一人]
[愿得一人] 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:39

    It turns out that they have added a "provided" configuration in the gradle android plugin 0.8.0 but it doesn't quite work. It does add the provided libraries to the compile path automatically, but it also includes them in the final aar/apk.

    What worked for me was the solution provided by @lukas-hanaceck but by changing the name from "provided" to any other custom name. In my case this is a library project which is a dependency for my final android application project. Heres a gist of what worked for me.

    configurations {
       providedlibs
    }
    
    dependencies {
       providedlibs files('provided/library.jar')
    }
    
    libraryVariants.all {
        variant -> variant.javaCompile.classpath += configurations.providedlibs
    }
    

    It compiles perfectly and the provided/library.jar is not included in the final apk. The only issue I am having is notifying Android studio of the existence of library.jar. The idea plugin doesn't seem to work for Android studio. Im guessing that they have another custom plugin for syncing gradle with studio.

提交回复
热议问题