Spec artifacts
The contents of a deploy spec (e.g. AARs, JARs, additional artifacts like sources or javadocs) can be configured in the content {}
block.
Each spec can support multiple components, each one corresponding to a maven publication and pom file.
Built-in components
Inside the content {}
block, a few utilities are available so that:
- You give us some hints about the kind of project that you are working on
- We infer a list of components that you will want to export
Kotlin Multiplatform projects
Use content.kotlinComponents()
. The spec will export:
- One component for Kotlin Metadata (the
common
target) - One component per declared kotlin target
If your Kotlin project includes Android, you should also use
androidComponents()
.
kotlincontent {
kotlinComponents {
// Optional configuration, invoked on each component.
}
}
Kotlin regular projects
Again, use content.kotlinComponents()
. The spec will export a single component based for the desired platform.
If your Kotlin project targets Android, you should use
androidComponents()
instead.
kotlincontent {
kotlinComponents {
// Optional configuration, invoked on the component.
}
}
Android projects
Use content.androidComponents("softwareComponentName")
for Android projects. This function accepts a vararg
list of software component names, which you must declare in the regular android {}
configuration.
Unfortunately, Android Gradle Plugin offers no API to read the variants that you configured for publishing, so the exact names must be passed to the deployer, too.
kotlinandroid {
publishing {
singleVariant("release")
multipleVariants("merged") { includeBuildTypeValues("debug", "release") }
}
}
content {
androidComponents("release", "merged") {
// Optional configuration, invoked on each component.
}
}
Gradle Plugin projects
For projects providing gradle plugins, it is expected that the java-gradle-plugin
is applied
and that you declare some plugins through the official gradlePlugin { }
block. It is also expected that
automated publishing is enabled:
kotlinplugins {
`java-gradle-plugin`
}
gradlePlugin {
isAutomatedPublishing = true
plugins {
create("myplugin") {
id = "com.my.package.myplugin"
implementationClass = "com.my.package.subpackage.MyPlugin"
}
}
}
All of the above are Gradle APIs, not deployer's.
Then, you can use content.gradlePluginComponents()
for the deployer spec to collect this data and export it.
The spec will be configured to have one component for the project, and one gradle marker component for each plugin in gradlePlugin.plugins
.
To understand about plugin markers and java-gradle-plugin
, please check out Gradle documentation.
kotlincontent {
gradlePluginComponents {
// Optional configuration, invoked on the component.
}
}
Custom components
To declare custom components, simply add them, one by one, with content.component { ... }
. Multiple types of components are supported:
- Based on an existing Gradle SoftwareComponent
- Based on an existing Gradle MavenPublication
- Based on an existing Gradle
PluginDeclaration
- Based on an existing
KotlinTarget
(except Android targets, which may map to multiple components) - A custom list of artifacts
kotlindeployer {
content {
component {
fromSoftwareComponent("softwareComponentName")
}
component {
fromSoftwareComponent(mySoftwareComponentInstance)
}
component {
// cloning the publication makes sure that it can be shared across multiple specs.
fromMavenPublication("mavenPublicationName", clone = false)
}
component {
fromKotlinTarget(myKotlinTarget)
}
component {
fromGradlePluginDeclaration(myGradlePlugin)
}
component {
fromJava() // shorthand for fromSoftwareComponent("java")
}
component {
fromArtifactSet {
artifact(myArtifact, builtBy = myArtifactTask)
artifact(myArtifact, classifier = "data", extension = "zip", builtBy = myArtifactTask)
}
}
}
}
Component extras
The component builders mentioned above describe the main published artifact (for example, a jar with binary code). It is possible however to add more files to the publication:
- sources: use
component.sources(mySourcesTask)
- javadocs: use
component.docs(myJavadocTask)
- other artifacts: use
component.extras.artifact(...)
You can also leverage sources and docs utilities. Use:
content.emptyDocs()
to create an empty docs JAR. Useful for repositories that require this artifact to exist.content.emptySources()
to create an empty sources JAR. Useful for repositories that require this artifact to exist.content.kotlinSources()
to add a Kotlin-based sources JAR. Note that this is not needed for KMP, where sources are automatically exported by the Kotlin Gradle Plugin.content.javaSources()
to add a Java-based sources JAR.
More
- Free Doc Hosting
- Newsletter