Class ApiOnlySubscriberExtension
apiOnlySubscriber block: which contracts this project builds
against, and where they come from.
apiOnlySubscriber {
channel {
type = 'maven'
groupId = 'com.example.contracts'
}
subscribe('user-account') {
version = '2.1.0'
}
}
One channel serves every subscription in a project. Each subscription can
carry its own version, because contracts are versioned independently; one that
does not takes getVersion().
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionApiOnlySubscriberExtension(org.gradle.api.model.ObjectFactory objects) Creates the extension. -
Method Summary
Modifier and TypeMethodDescriptionvoidchannel(org.gradle.api.Action<? super ChannelSpec> action) Configures the channel.The channel every subscription in this project resolves through.abstract org.gradle.api.file.RegularFilePropertyWhere the resolved versions and file hashes are recorded.org.gradle.api.NamedDomainObjectContainer<Subscription> Every declared subscription, keyed by target name.abstract org.gradle.api.provider.Property<String> The contract version every subscription in this project resolves, unless it sets its own.Declares a subscription without configuring it.subscribe(String target, org.gradle.api.Action<? super Subscription> action) Declares a subscription and configures it.subscription(String target) Looks up a declared subscription, so a build file can wire its documents into whatever consumes them.
-
Field Details
-
NAME
The name used to register this extension in a consumer build.- See Also:
-
-
Constructor Details
-
ApiOnlySubscriberExtension
@Inject public ApiOnlySubscriberExtension(org.gradle.api.model.ObjectFactory objects) Creates the extension.Gradle instantiates this when the plugin is applied; a build script configures the instance registered as
apiOnlySubscriber.- Parameters:
objects- Gradle's object factory, supplied by injection
-
-
Method Details
-
getChannel
The channel every subscription in this project resolves through.- Returns:
- the channel specification
-
channel
Configures the channel.channel { type = 'file' directory = "$rootDir/build/publish" }- Parameters:
action- configuration applied to the channel specification
-
getSubscriptions
Every declared subscription, keyed by target name.- Returns:
- the container of subscriptions
-
subscribe
Declares a subscription and configures it.subscribe('user-account') { version = '2.1.0' }Subscribing to the same target twice configures the existing subscription rather than creating a second one.
- Parameters:
target- the contract to subscribe toaction- configuration applied to the subscription- Returns:
- the subscription, so it can be referenced immediately
-
subscribe
Declares a subscription without configuring it.Only useful when the version is set later, since a subscription with no version fails the build when it is resolved.
- Parameters:
target- the contract to subscribe to- Returns:
- the subscription
-
subscription
Looks up a declared subscription, so a build file can wire its documents into whatever consumes them.apiOnlySuite { rootDocument = apiOnlySubscriber.subscription('user-account').openapi }- Parameters:
target- the subscribed contract to look up- Returns:
- the subscription for that target
- Throws:
IllegalArgumentException- if no such subscription was declared; the message lists the targets that were
-
getLockfile
public abstract org.gradle.api.file.RegularFileProperty getLockfile()Where the resolved versions and file hashes are recorded.Defaults to
apionly.lockbeside the build file. It is shared by every subscription in the project and is meant to be committed: it is whatVerifyApiSpecTaskchecks the fetched documents against, and what makes "which contract is this project actually building against?" a question answerable by reading the repository.- Returns:
- the lockfile location
-
getVersion
The contract version every subscription in this project resolves, unless it sets its own.Defaults to the
apiContractVersionproject property, so the version can live ingradle.properties-- in a multi-project build, the subproject's own -- or be given with-PapiContractVersion=...orORG_GRADLE_PROJECT_apiContractVersion.apiOnlySubscriber { version = '2.1.0' subscribe('user-account') }- Returns:
- the default contract version; unset when the property is not defined
-