Gradle java-library plugin compared to java-plugin

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-libraryroot file build.gradlecould 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 sourceCompatibilityboth are targetCompatibilitydetermined sourceCompatibility targetCompatibility javaand 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 javaplugin and that Java libraries use the java-libraryplugin? Is there a reason why the plugin javashould 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 ?

+6
3

docs

[...] Java Library java.

, - , . . java subprojects, java-library , ( build.gradle).

, , , withPlugin PluginManager withId PluginContainer. :

, . , . , .

subprojects { sub ->
    sub.plugins.withId('java-library') {
        // configure sub
    }
}
+2

, : api implementation.

:

api , API, implementation , .

Gradle 3.4 Java-, , , .
api compile, .

0

, : .

- java java-library ?

Java Library, jar, Java. , , Gradle jar . .

, .

Gradle 5.3 , Groovy, .

0

Source: https://habr.com/ru/post/1687065/


All Articles