Package org.gradle.api.plugins

## Interface JavaPluginExtension

-     public interface JavaPluginExtension

  Common configuration for Java based projects. This is added by the `JavaBasePlugin`.
  Since:
    4.10

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `consistentResolution​(Action<? super JavaResolutionConsistency> action)` | Configure the dependency resolution consistency for this Java project.
    `void` | `disableAutoTargetJvm()` | If this method is called, Gradle will not automatically try to fetch dependencies which have a JVM version compatible with the target compatibility of this module.
    `boolean` | `getAutoTargetJvmDisabled()` | Tells if automatic JVM targeting is enabled.
    `DirectoryProperty` | `getDocsDir()` | Returns a file pointing to the root directory supposed to be used for all docs.
    `ModularitySpec` | `getModularity()` | Configure the module path handling for tasks that have a 'classpath' as input.
    `JavaVersion` | `getSourceCompatibility()` | Returns the source compatibility used for compiling Java sources.
    `SourceSetContainer` | `getSourceSets()` | The source sets container.
    `JavaVersion` | `getTargetCompatibility()` | Returns the target compatibility used for compiling Java sources.
    `DirectoryProperty` | `getTestReportDir()` | Returns a file pointing to the root directory to be used for reports.
    `DirectoryProperty` | `getTestResultsDir()` | Returns a file pointing to the root directory of the test results.
    `JavaToolchainSpec` | `getToolchain()` | Gets the project wide toolchain requirements that will be used for tasks requiring a tool from the toolchain (e.g.
    `Manifest` | `manifest()` | Creates a new instance of a `Manifest`.
    `Manifest` | `manifest​(Closure closure)` | Creates and configures a new instance of a `Manifest`.
    `Manifest` | `manifest​(Action<? super Manifest> action)` | Creates and configures a new instance of a `Manifest`.
    `void` | `registerFeature​(String name, Action<? super FeatureSpec> configureAction)` | Registers a feature.
    `void` | `setSourceCompatibility​(Object value)` | Sets the source compatibility used for compiling Java sources.
    `void` | `setSourceCompatibility​(JavaVersion value)` | Sets the source compatibility used for compiling Java sources.
    `void` | `setTargetCompatibility​(Object value)` | Sets the target compatibility used for compiling Java sources.
    `void` | `setTargetCompatibility​(JavaVersion value)` | Sets the target compatibility used for compiling Java sources.
    `Object` | `sourceSets​(Closure closure)` | Configures the source sets of this project.
    `JavaToolchainSpec` | `toolchain​(Action<? super JavaToolchainSpec> action)` | Configures the project wide toolchain requirements for tasks that require a tool from the toolchain (e.g.
    `void` | `withJavadocJar()` | Adds a task `javadocJar` that will package the output of the `javadoc` task in a JAR with classifier `javadoc`.
    `void` | `withSourcesJar()` | Adds a task `sourcesJar` that will package the Java sources of the main `SourceSet` in a JAR with classifier `sources`.

- - ### Method Detail

    - #### getSourceCompatibility

          JavaVersion getSourceCompatibility()

      Returns the source compatibility used for compiling Java sources.

    - #### setSourceCompatibility

          void setSourceCompatibility​(JavaVersion value)

      Sets the source compatibility used for compiling Java sources.

      This property cannot be set if a `toolchain` has been configured.

      Parameters:
        `value` - The value for the source compatibility
      See Also:
        `toolchain(Action)`

    - #### getTargetCompatibility

          JavaVersion getTargetCompatibility()

      Returns the target compatibility used for compiling Java sources.

    - #### setTargetCompatibility

          void setTargetCompatibility​(JavaVersion value)

      Sets the target compatibility used for compiling Java sources.

      This property cannot be set if a `toolchain` has been configured.

      Parameters:
        `value` - The value for the target compatibility
      See Also:
        `toolchain(Action)`

    - #### registerFeature

          void registerFeature​(String name,
                               Action<? super FeatureSpec> configureAction)

      Registers a feature.

      The new feature will have a default capability corresponding to the "group", "name" + feature name and version of this project. For example, if the group of the component is "org", that the project name is "lib" the version is "1.0" and the feature name is "myFeature", then a capability named "org:lib-my-feature:1.0" is automatically added.

      In order to consume this feature in another module add a dependency like the following:

            dependencies {
                implementation(project(":lib")) {
                    capabilities {
                        requireCapability("org:lib-my-feature:1.0")
                    }
                }
            }

      The `FeatureSpec.capability(String, String, String)` method can be used to refine the capabilities of this feature.
      Parameters:
        `name` - the name of the feature
        `configureAction` - the configuration for the feature
      Since:
        5.3

    - #### disableAutoTargetJvm

          void disableAutoTargetJvm()

      If this method is called, Gradle will not automatically try to fetch dependencies which have a JVM version compatible with the target compatibility of this module.

      This should be used whenever the default behavior is not applicable, in particular when for some reason it's not possible to split a module and that this module only has some classes which require dependencies on higher versions.

      Since:
        5.3

    - #### withJavadocJar

          void withJavadocJar()

      Adds a task `javadocJar` that will package the output of the `javadoc` task in a JAR with classifier `javadoc`.

      The produced artifact is registered as a documentation variant on the `java` component and added as a dependency on the `assemble` task. This means that if `maven-publish` or `ivy-publish` is also applied, the javadoc JAR will be published.

      If the project already has a task named `javadocJar` then no task is created.

      The publishing of the Javadoc variant can also be disabled using `ConfigurationVariantDetails.skip()` through `AdhocComponentWithVariants.withVariantsFromConfiguration(Configuration, Action)`, if it should only be built locally by calling or wiring the ':javadocJar' task.

      Since:
        6.0

    - #### withSourcesJar

          void withSourcesJar()

      Adds a task `sourcesJar` that will package the Java sources of the main `SourceSet` in a JAR with classifier `sources`.

      The produced artifact is registered as a documentation variant on the `java` component and added as a dependency on the `assemble` task. This means that if `maven-publish` or `ivy-publish` is also applied, the sources JAR will be published.

      If the project already has a task named `sourcesJar` then no task is created.

      The publishing of the sources variant can be disabled using `ConfigurationVariantDetails.skip()` through `AdhocComponentWithVariants.withVariantsFromConfiguration(Configuration, Action)`, if it should only be built locally by calling or wiring the ':sourcesJar' task.

      Since:
        6.0

    - #### getModularity

          ModularitySpec getModularity()

      Configure the module path handling for tasks that have a 'classpath' as input. The module classpath handling defines to determine for each entry if it is passed to Java tools using '-classpath' or '--module-path'.
      Since:
        6.4

    - #### getToolchain

          JavaToolchainSpec getToolchain()

      Gets the project wide toolchain requirements that will be used for tasks requiring a tool from the toolchain (e.g. `JavaCompile`).

      Configuring a toolchain cannot be used together with `sourceCompatibility` or `targetCompatibility` on this extension. Both values will be sourced from the toolchain.

      Since:
        6.7

    - #### toolchain

          JavaToolchainSpec toolchain​(Action<? super JavaToolchainSpec> action)

      Configures the project wide toolchain requirements for tasks that require a tool from the toolchain (e.g. `JavaCompile`).

      Configuring a toolchain cannot be used together with `sourceCompatibility` or `targetCompatibility` on this extension. Both values will be sourced from the toolchain.

      Since:
        6.7

    - #### consistentResolution

          @Incubating
          void consistentResolution​(Action<? super JavaResolutionConsistency> action)

      Configure the dependency resolution consistency for this Java project.
      Parameters:
        `action` - the configuration action
      Since:
        6.8

    - #### sourceSets

          Object sourceSets​(Closure closure)

      Configures the source sets of this project.

      The given closure is executed to configure the `SourceSetContainer`. The `SourceSetContainer` is passed to the closure as its delegate.

      See the example below how `SourceSet` 'main' is accessed and how the `SourceDirectorySet` 'java' is configured to exclude some package from compilation.

           plugins {
               id 'java'
           }

           sourceSets {
             main {
               java {
                 exclude 'some/unwanted/package/**'
               }
             }
           }

      Parameters:
        `closure` - The closure to execute.
      Returns:
        NamedDomainObjectContainer<org.gradle.api.tasks.SourceSet>
      Since:
        7.1

    - #### getDocsDir

          DirectoryProperty getDocsDir()

      Returns a file pointing to the root directory supposed to be used for all docs.
      Since:
        7.1

    - #### getTestResultsDir

          DirectoryProperty getTestResultsDir()

      Returns a file pointing to the root directory of the test results.
      Since:
        7.1

    - #### getTestReportDir

          DirectoryProperty getTestReportDir()

      Returns a file pointing to the root directory to be used for reports.
      Since:
        7.1

    - #### setSourceCompatibility

          void setSourceCompatibility​(Object value)

      Sets the source compatibility used for compiling Java sources.
      Parameters:
        `value` - The value for the source compatibility as defined by `JavaVersion.toVersion(Object)`
      Since:
        7.1

    - #### setTargetCompatibility

          void setTargetCompatibility​(Object value)

      Sets the target compatibility used for compiling Java sources.
      Parameters:
        `value` - The value for the target compatibility as defined by `JavaVersion.toVersion(Object)`
      Since:
        7.1

    - #### manifest

          Manifest manifest()

      Creates a new instance of a `Manifest`.
      Since:
        7.1

    - #### manifest

          Manifest manifest​(Closure closure)

      Creates and configures a new instance of a `Manifest`. The given closure configures the new manifest instance before it is returned.
      Parameters:
        `closure` - The closure to use to configure the manifest.
      Since:
        7.1

    - #### manifest

          Manifest manifest​(Action<? super Manifest> action)

      Creates and configures a new instance of a `Manifest`.
      Parameters:
        `action` - The action to use to configure the manifest.
      Since:
        7.1

    - #### getSourceSets

          SourceSetContainer getSourceSets()

      The source sets container.
      Since:
        7.1

    - #### getAutoTargetJvmDisabled

          boolean getAutoTargetJvmDisabled()

      Tells if automatic JVM targeting is enabled. When disabled, Gradle will not automatically try to get dependencies corresponding to the same (or compatible) level as the target compatibility of this module.
      Since:
        7.1