api / org.gradle.jvm.tasks.api / ApiJar

ApiJar

@Incubating open class ApiJar : SourceTask

Assembles an "API Jar" containing only the members of a library's public API.

This task and the Jar it produces are designed primarily for internal use in support of Gradle's "compile avoidance" performance feature. The task is automatically included in the task graph for any JVM library that declares an api { ... } specification, and the resulting Jar will automatically be placed on the compile time classpath of projects that depend on the library in lieu of the library's complete so-called "Runtime Jar".

Swapping the API Jar in for the Runtime Jar at compile time is what makes "compile avoidance" possible: because the contents of the API Jar change only when actual API changes are made, the API Jar passes Gradle's up-to-date checks, even if the implementation in the Runtime Jar has changed. Ultimately, this means that projects depending on the library in question will need to recompile potentially far less often.

In order to ensure that API Jars change as infrequently as possible, this task and its supporting classes ensure that only actual public API members are included in the API Jar, and that the methods among those members are stripped of their implementation. Because the members included in API Jars exist only for compilation purposes, they need no actual implementation, and for this reason, all such methods throw UnsupportedOperationException in the unlikely event that they are present on the classpath and invoked at runtime.

The inputs to this task are Java class files which must be provided via org.gradle.api.tasks.TaskInputs.

Since
2.10

See Also
org.gradle.jvm.plugins.JvmComponentPlugin

Constructors

<init>

ApiJar()

Assembles an "API Jar" containing only the members of a library's public API.

This task and the Jar it produces are designed primarily for internal use in support of Gradle's "compile avoidance" performance feature. The task is automatically included in the task graph for any JVM library that declares an api { ... } specification, and the resulting Jar will automatically be placed on the compile time classpath of projects that depend on the library in lieu of the library's complete so-called "Runtime Jar".

Swapping the API Jar in for the Runtime Jar at compile time is what makes "compile avoidance" possible: because the contents of the API Jar change only when actual API changes are made, the API Jar passes Gradle's up-to-date checks, even if the implementation in the Runtime Jar has changed. Ultimately, this means that projects depending on the library in question will need to recompile potentially far less often.

In order to ensure that API Jars change as infrequently as possible, this task and its supporting classes ensure that only actual public API members are included in the API Jar, and that the methods among those members are stripped of their implementation. Because the members included in API Jars exist only for compilation purposes, they need no actual implementation, and for this reason, all such methods throw UnsupportedOperationException in the unlikely event that they are present on the classpath and invoked at runtime.

The inputs to this task are Java class files which must be provided via org.gradle.api.tasks.TaskInputs.

Functions

createApiJar

open fun createApiJar(): Unit

getExportedPackages

open fun getExportedPackages(): MutableSet<String>

getOutputFile

open fun getOutputFile(): File

setExportedPackages

open fun setExportedPackages(exportedPackages: MutableSet<String>): Unit

setOutputFile

open fun setOutputFile(outputFile: File): Unit

Inherited Functions

exclude

open fun exclude(vararg excludes: String): SourceTask
open fun exclude(excludes: MutableIterable<String>): SourceTask
open fun exclude(excludeSpec: Spec<FileTreeElement>): SourceTask
open fun exclude(excludeSpec: Closure<Any>): SourceTask

{@inheritDoc}

getExcludes

open fun getExcludes(): MutableSet<String>

{@inheritDoc}

getIncludes

open fun getIncludes(): MutableSet<String>

{@inheritDoc}

getSource

open fun getSource(): FileTree

Returns the source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.

include

open fun include(vararg includes: String): SourceTask
open fun include(includes: MutableIterable<String>): SourceTask
open fun include(includeSpec: Spec<FileTreeElement>): SourceTask
open fun include(includeSpec: Closure<Any>): SourceTask

{@inheritDoc}

setExcludes

open fun setExcludes(excludes: MutableIterable<String>): SourceTask

{@inheritDoc}

setIncludes

open fun setIncludes(includes: MutableIterable<String>): SourceTask

{@inheritDoc}

setSource

open fun setSource(source: FileTree): Unit

Sets the source for this task.

open fun setSource(source: Any): Unit

Sets the source for this task. The given source object is evaluated as per org.gradle.api.Project#files(Object...).

source

open fun source(vararg sources: Any): SourceTask

Adds some source to this task. The given source objects will be evaluated as per org.gradle.api.Project#files(Object...).