How to use provided scope for jar file in Gradle build?

Dependency packages are sometimes duplicated and sometimes conflicted

The maven scope has the provided attribute, which will not cause dependencies to conflict with some jar packages that come with large frameworks

 

Gradle also has several scopes:

Gradle compile:

If your jar package/dependent code needs dependencies at compile time and also at runtime, use compile
for example:

compile 'org.springframework:spring-webmvc:4.3.9.RELEASE'

  

Premise: apply plugin: 'war'orapply plugin: 'java'

 

Gradle providedCompile:

If your jar/dependency code is only needed at compile time, but doesn't need dependencies at runtime, use providedCompile
for example:

compileOnly group: 'javax.servlet.jsp.jstl', name: 'jstl', version: '1.2'

 

premise:apply plugin: 'war'

 

Gradle runtime:

If your jar/dependency code is only needed at runtime, but doesn't need dependencies at compile time, use runtime
for example:

runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.42'

 

premise:apply plugin: 'java'

 

If the premise mentioned above is not configured correctly, it will encounter the situation that the dependent package cannot be imported, and the runtime and providedCompile cannot be used.

The higher version of gradle does not have providedCompile

 

Reference: https://stackoverflow.com/questions/18738888/how-to-use-provided-scope-for-jar-file-in-gradle-build

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326105504&siteId=291194637