The Gradle documentation for the java-library plugin says:
The Java Library plugin extends the capabilities of the Java plugin by providing specific knowledge about Java libraries. In particular, the Java library provides APIs to users (that is, other projects using the Java plugin or Java library).
This statement implies that only java programs intended for use (libraries) should use the plugin java-library
; while Java programs that are not intended to be used (applications) should use the plugin java
.
Before using the plugin, the java-library
root file build.gradle
could contain the following:
subprojects {
apply plugin: 'java'
sourceCompatibility '1.8'
targetCompatibility '1.8'
// other common java stuff
}
However, now in multi-module projects that have both applications and libraries, you cannot delegate the choice of plugins to subprojects and have the following root build.gradle
:
subprojects {
sourceCompatibility '1.8'
targetCompatibility '1.8'
// other common java stuff
}
This will not succeed, because sourceCompatibility
both are targetCompatibility
determined sourceCompatibility
targetCompatibility
java
and java-library
. Ideally, I would like to do the following:
subprojects {
apply plugin: 'java-library'
sourceCompatibility '1.8'
targetCompatibility '1.8'
// other common java stuff
}
Is there any reason to ensure that Java applications use the java
plugin and that Java libraries use the java-library
plugin? Is there a reason why the plugin java
should be used instead of the plugin java-library
?
edit
, Gradle java
java-library
. java
build.grade apply plugin: 'java'
. build.gradle java-library
. apply plugin: 'java'
; utils apply plugin: 'java-library'
.
: java
java-library
? , . sourceCompatibility
targetCompatibility
. , , , java-library
.
- java
java-library
?