Skip to content

Commit

Permalink
fix: correct publication configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Artyom Shendrik <artyom.shendrik@gmail.com>
  • Loading branch information
amal committed Dec 24, 2023
1 parent 6f7702b commit 1b155cd
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 50 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

[//]: # (Removed, Added, Changed, Fixed, Updated)

### Fixed

- correct publication configuration.
- workaround Gradle 8+ problems with publication.
- correct the Gradle Versions Plugin setup.

### Updated
- pin Okio version to 3.7.0 due to the Security Advisory [CVE-2023-3635](https://github.com/advisories/GHSA-w33c-445m-f8w7).


## [0.4.0] - 2023-12-20

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.sam.receiver) apply false
alias(libs.plugins.kotlinx.binCompatValidator) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.deps.guard) apply false
alias(libs.plugins.gradle.plugin.publish) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.fluxo.conf)
}
5 changes: 5 additions & 0 deletions checks/gradle-plugin/dependencies/classpath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ com.diffplug.spotless:spotless-lib:2.43.1
com.diffplug.spotless:spotless-plugin-gradle:6.23.3
com.dropbox.dependency-guard:com.dropbox.dependency-guard.gradle.plugin:0.4.3
com.dropbox.dependency-guard:dependency-guard:0.4.3
com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin:0.50.0
com.github.ben-manes:gradle-versions-plugin:0.50.0
com.googlecode.concurrent-trees:concurrent-trees:2.6.1
com.googlecode.java-diff-utils:diffutils:1.3.0
com.googlecode.javaewah:JavaEWAH:1.2.3
com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:1.2.1
com.gradle.publish:plugin-publish-plugin:1.2.1
com.squareup.moshi:moshi-kotlin:1.12.0
com.squareup.moshi:moshi:1.12.0
com.squareup.okhttp3:okhttp:4.11.0
com.squareup.okio:okio-jvm:3.2.0
com.squareup.okio:okio:3.2.0
Expand Down Expand Up @@ -40,6 +44,7 @@ org.jetbrains.kotlin:kotlin-gradle-plugins-bom:1.9.21
org.jetbrains.kotlin:kotlin-klib-commonizer-api:1.9.21
org.jetbrains.kotlin:kotlin-native-utils:1.9.21
org.jetbrains.kotlin:kotlin-project-model:1.9.21
org.jetbrains.kotlin:kotlin-reflect:1.9.20
org.jetbrains.kotlin:kotlin-scripting-common:1.9.21
org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.9.21
org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:1.9.21
Expand Down
4 changes: 4 additions & 0 deletions checks/main/dependencies/classpath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ com.diffplug.spotless:spotless-lib:2.43.1
com.diffplug.spotless:spotless-plugin-gradle:6.23.3
com.dropbox.dependency-guard:com.dropbox.dependency-guard.gradle.plugin:0.4.3
com.dropbox.dependency-guard:dependency-guard:0.4.3
com.github.ben-manes.versions:com.github.ben-manes.versions.gradle.plugin:0.50.0
com.github.ben-manes:gradle-versions-plugin:0.50.0
com.google.android:annotations:4.1.1.4
com.google.api.grpc:proto-google-common-protos:2.0.1
com.google.auto.value:auto-value-annotations:1.6.2
Expand All @@ -72,6 +74,8 @@ com.google.testing.platform:core-proto:0.0.8-alpha08
com.googlecode.concurrent-trees:concurrent-trees:2.6.1
com.googlecode.javaewah:JavaEWAH:1.2.3
com.googlecode.juniversalchardet:juniversalchardet:1.0.3
com.squareup.moshi:moshi-kotlin:1.12.0
com.squareup.moshi:moshi:1.12.0
com.squareup.okhttp3:okhttp:4.11.0
com.squareup.okio:okio-jvm:3.2.0
com.squareup.okio:okio:3.2.0
Expand Down
3 changes: 3 additions & 0 deletions fluxo-kmp-conf/api/plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,15 @@ public abstract interface class fluxo/conf/dsl/FluxoConfigurationExtensionAndroi

public abstract interface class fluxo/conf/dsl/FluxoConfigurationExtensionCommon {
public abstract fun getEnableBuildConfig ()Z
public abstract fun getEnableDetektAutoCorrect ()Ljava/lang/Boolean;
public abstract fun getEnableDetektCompilerPlugin ()Ljava/lang/Boolean;
public abstract fun getEnableSpotless ()Ljava/lang/Boolean;
public fun getEnableVerification ()Ljava/lang/Boolean;
public abstract fun getSetupDependencies ()Z
public abstract fun getSetupKnownBoms ()Z
public abstract fun getSetupVerification ()Ljava/lang/Boolean;
public abstract fun setEnableBuildConfig (Z)V
public abstract fun setEnableDetektAutoCorrect (Ljava/lang/Boolean;)V
public abstract fun setEnableDetektCompilerPlugin (Ljava/lang/Boolean;)V
public abstract fun setEnableSpotless (Ljava/lang/Boolean;)V
public fun setEnableVerification (Ljava/lang/Boolean;)V
Expand All @@ -230,6 +232,7 @@ public abstract interface class fluxo/conf/dsl/FluxoConfigurationExtensionCommon

public abstract interface class fluxo/conf/dsl/FluxoConfigurationExtensionKotlin : fluxo/conf/dsl/FluxoConfigurationExtensionKotlinOptions {
public fun apiValidation (Lkotlin/jvm/functions/Function1;)V
public static synthetic fun apiValidation$default (Lfluxo/conf/dsl/FluxoConfigurationExtensionKotlin;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public abstract fun getAddStdlibDependency ()Z
public abstract fun getApiValidation ()Lfluxo/conf/dsl/BinaryCompatibilityValidatorConfig;
public abstract fun getEnableApiValidation ()Ljava/lang/Boolean;
Expand Down
5 changes: 2 additions & 3 deletions fluxo-kmp-conf/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<ID>ForbiddenComment:SetupKotlinOptions.kt$// TODO: &amp;&amp; kotlinLang >= KotlinLangVersion.KOTLIN_1_7</ID>
<ID>ForbiddenComment:SetupKotlinOptions.kt$// TODO: Allow -Xjdk-release=1.6 with -jvm-target 1.8 once it is supported</ID>
<ID>ForbiddenComment:SetupKotlinOptions.kt$// TODO: Make conversion of Compose Compiler metrics to HTML automatically with Gradle.</ID>
<ID>ForbiddenComment:SetupPublication.kt$// FIXME: provide sources for KMP publications</ID>
<ID>ForbiddenComment:SetupPublication.kt$// TODO: Add support for multiple developers</ID>
<ID>ForbiddenComment:SetupPublication.kt$// TODO: Add support for multiple licenses</ID>
<ID>ForbiddenComment:SetupPublication.kt$// TODO: Decorate the build logs with maven coordinates of published artifacts</ID>
Expand All @@ -92,6 +93,7 @@
<ID>ForbiddenComment:TargetAndroidContainer.kt$TargetAndroidContainer$// FIXME: Implement API for source sets.</ID>
<ID>ForbiddenComment:TargetAndroidContainer.kt$TargetAndroidContainer$// TODO: provide a `setupParentSourceSet` with a single SourceSet arg</ID>
<ID>ForbiddenComment:TargetAndroidContainer.kt$TargetAndroidContainer$// TODO: should androidUnitTestDebug depend on androidUnitTest?</ID>
<ID>Indentation:DependencyUpdatesPlugin.kt.kt$ </ID>
<ID>Indentation:FluxoConfigurationExtensionAndroidImpl.kt$FluxoConfigurationExtensionAndroidImpl$ </ID>
<ID>Indentation:PropsAndEnv.kt$ </ID>
<ID>Indentation:SetupKotlin.kt$ </ID>
Expand All @@ -101,7 +103,6 @@
<ID>LongMethod:SetupKotlin.kt$internal fun configureKotlinJvm( type: ConfigurationType, configuration: FluxoConfigurationExtensionImpl, containers: Array&lt;Container>, ): Boolean</ID>
<ID>LongMethod:SetupTestsReport.kt$internal fun FluxoKmpConfContext.setupTestsReport()</ID>
<ID>LongMethod:TestReportsMergeTask.kt$TestReportsMergeTask$@TaskAction fun merge()</ID>
<ID>LongParameterList:SetupIdeaPlugin.kt$( config: (FluxoConfigurationExtension.() -> Unit)? = null, group: String? = null, version: String? = null, sinceBuild: String, intellijVersion: String, body: (KotlinJvmProjectExtension.() -> Unit)? = null, )</ID>
<ID>LoopWithTooManyJumpStatements:FluxoConfigurationExtensionImpl.kt$FluxoConfigurationExtensionImpl$while</ID>
<ID>MagicNumber:SetupKotlin.kt$11</ID>
<ID>MaxLineLength:DependencyGuardPlugin.kt$/** @see com.dropbox.gradle.plugins.dependencyguard.internal.ConfigurationValidators.isClasspathConfig */</ID>
Expand All @@ -116,7 +117,6 @@
<ID>MaxLineLength:PropsAndEnv.kt$if</ID>
<ID>MaxLineLength:SetupJvmCompatibility.kt$(this as? ExtensionAware)</ID>
<ID>MaxLineLength:SetupKotlinDependencies.kt$implementationAndLog(if (isApplication) dh.enforcedPlatform(it) else dh.platform(it))</ID>
<ID>MaxLineLength:SetupKotlinOptions.kt$if</ID>
<ID>MaxLineLength:SetupMultiplatform.kt$*</ID>
<ID>MaxLineLength:SetupTestsReport.kt$description = "Combines all tests reports from all modules to the published root one"</ID>
<ID>MaxLineLength:SetupTestsReport.kt$if</ID>
Expand All @@ -127,7 +127,6 @@
<ID>MaximumLineLength:PropsAndEnv.kt$ </ID>
<ID>MaximumLineLength:SetupJvmCompatibility.kt$ </ID>
<ID>MaximumLineLength:SetupKotlinDependencies.kt$ </ID>
<ID>MaximumLineLength:SetupKotlinOptions.kt$ </ID>
<ID>MaximumLineLength:SetupTestsReport.kt$ </ID>
<ID>MaximumLineLength:VersionCatalogUtils.kt$internal</ID>
<ID>MultiLineIfElse:DependencyPinningBundle.kt$for (alias in bundleAliases) { // Filter "pinned and "pinned.*" bundles alias.startsWith(ALIAS, ignoreCase = true) &amp;&amp; alias.run { val l = length l == ALIAS.length || l > ALIAS.length &amp;&amp; this[ALIAS.length] == '.' } || continue val bundle = libs.b(alias)?.get() if (bundle.isNullOrEmpty()) { continue } logger.l("Pinning ${bundle.size} dependencies from version catalog bundle '$alias'") val reason = "$PIN_REASON from bundle '$alias'" for (dep in bundle) { val constraint = dep.versionConstraint.toString() with(rootProject) { logDependency("pinned", dep, " ('$alias' constraint)") } pinnedDeps[dep.module] = Pair(constraint, reason) } }</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public interface FluxoConfigurationExtensionKotlin : FluxoConfigurationExtension
* Flag to use the KotlinX Dokka plugin as a documentation artifact generator.
*
* Inherited from the parent project if not set.
* Default value: `false`.
* Default value: `true`.
*/
public var useDokka: Boolean?

Expand Down
113 changes: 68 additions & 45 deletions fluxo-kmp-conf/src/main/kotlin/fluxo/conf/feat/SetupPublication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import fluxo.conf.impl.get
import fluxo.conf.impl.getByName
import fluxo.conf.impl.has
import fluxo.conf.impl.hasExtension
import fluxo.conf.impl.kotlin.KOTLIN_EXT
import fluxo.conf.impl.kotlin.multiplatformExtension
import fluxo.conf.impl.l
import fluxo.conf.impl.namedOrNull
Expand All @@ -48,7 +47,7 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType


Expand Down Expand Up @@ -154,8 +153,14 @@ private fun Project.setupPublicationMultiplatform(
return
}

// FIXME: provide sources for KMP publications
val publishing = applyMavenPublishPlugin(config)
setupPublicationExtension(publishing, config, useDokka = useDokka)
setupPublicationExtension(
publishing = publishing,
config = config,
useDokka = useDokka,
type = ConfigurationType.GRADLE_PLUGIN,
)
setupPublicationRepositoryAndSigning(config, publishing)

multiplatformExtension.apply {
Expand Down Expand Up @@ -184,20 +189,21 @@ private fun Project.setupPublicationAndroidLibrary(

val androidExtension = the<LibraryExtension>()

val sourcePaths = androidExtension.sourceSets.getByName(MAIN_SOURCE_SET_NAME).java.srcDirs
val sourcePaths = androidExtension.sourceSets[MAIN_SOURCE_SET_NAME].java.srcDirs
val sourceJarTask = registerSourceJarTask(sourcePaths)
val javadocTask = setupJavadocTask(config, useDokka = useDokka)

fun PublicationContainer.createMavenPublication(name: String, artifactIdSuffix: String) {
create<MavenPublication>(name) {
from(components[name])
artifact(sourceJarTask)
artifact(javadocTask)

val project = project
groupId = config.group
version = config.version
artifactId = "${project.name}$artifactIdSuffix"

setupJavadocTask(project, config, useDokka = useDokka)
setupPublicationPom(project, config)
}
}
Expand Down Expand Up @@ -228,11 +234,18 @@ private fun Project.setupPublicationGradlePlugin(
config.publicationUrl?.let { vcsUrl.set(it) }
}

val sourcePaths = gradlePluginExtension.pluginSourceSet.java.srcDirs
val sourcePaths = gradlePluginExtension.pluginSourceSet.java.srcDirs +
kotlinExtension.sourceSets[MAIN_SOURCE_SET_NAME].kotlin.srcDirs
val sourceJarTask = registerSourceJarTask(sourcePaths)

// TODO: Should wrap `setupPublicationExtension` in afterEvaluate?
setupPublicationExtension(publishing, config, sourceJarTask, useDokka = useDokka)
setupPublicationExtension(
publishing = publishing,
config = config,
useDokka = useDokka,
sourceJarTask = sourceJarTask,
type = ConfigurationType.GRADLE_PLUGIN,
)

setupPublicationRepositoryAndSigning(config, publishing, mavenRepo = false)
}
Expand All @@ -248,12 +261,10 @@ private fun Project.setupPublicationKotlinJvm(

val publishing = applyMavenPublishPlugin(config)

val kotlinExtension = extensions.getByName<KotlinJvmProjectExtension>(KOTLIN_EXT)

val sourcePaths = kotlinExtension.sourceSets.getByName(MAIN_SOURCE_SET_NAME).kotlin.srcDirs
val sourcePaths = kotlinExtension.sourceSets[MAIN_SOURCE_SET_NAME].kotlin.srcDirs
val sourceJarTask = registerSourceJarTask(sourcePaths)

setupPublicationExtension(publishing, config, sourceJarTask, useDokka = useDokka)
setupPublicationExtension(publishing, config, useDokka = useDokka, sourceJarTask)
setupPublicationRepositoryAndSigning(config, publishing)
}

Expand All @@ -267,10 +278,10 @@ private fun Project.setupPublicationJava(config: FluxoPublicationConfig) {

val javaPluginExtension = the<JavaPluginExtension>()

val sourcePaths = javaPluginExtension.sourceSets.getByName(MAIN_SOURCE_SET_NAME).java.srcDirs
val sourcePaths = javaPluginExtension.sourceSets[MAIN_SOURCE_SET_NAME].java.srcDirs
val sourceJarTask = registerSourceJarTask(sourcePaths)

setupPublicationExtension(publishing, config, sourceJarTask, useDokka = false)
setupPublicationExtension(publishing, config, useDokka = false, sourceJarTask)
setupPublicationRepositoryAndSigning(config, publishing)
}

Expand Down Expand Up @@ -402,25 +413,34 @@ context(FluxoKmpConfContext)
private fun Project.setupPublicationExtension(
publishing: PublishingExtension,
config: FluxoPublicationConfig,
sourceJarTask: Any? = null,
useDokka: Boolean,
sourceJarTask: Any? = null,
type: ConfigurationType? = null,
) {
val javadocTask = setupJavadocTask(config, useDokka = useDokka, type)
publishing.publications.withType<MavenPublication> {
val project = project
val pName = name

config.projectName?.let { projectName ->
if (artifactId.isNullOrBlank() || !projectName.equals(artifactId, ignoreCase = true)) {
val aid = artifactId
if (aid.isNullOrBlank() || !aid.startsWith(projectName, ignoreCase = true)) {
logger.l("publication '$pName': artifactId replace ($aid -> $projectName)")
artifactId = projectName
}
}
if (groupId.isNullOrBlank()) {
groupId = config.group
}

project.logger.l("setup maven publication '$name': '$groupId:$artifactId:$version'")
// Skip manual artifacts control for Gradle plugins
val skipArtifacts = type === ConfigurationType.GRADLE_PLUGIN

val coords = "$groupId:$artifactId:$version"
val artifacts = if (skipArtifacts) "" else "; artifacts added"
logger.l("setup maven publication '$pName': '$coords'$artifacts")

if (!skipArtifacts) {
sourceJarTask?.let { artifact(it) }
artifact(javadocTask)
}

sourceJarTask?.let { artifact(it) }
setupJavadocTask(project, config, useDokka = useDokka)
setupPublicationPom(project, config)
}
}
Expand Down Expand Up @@ -456,11 +476,11 @@ internal val Project.gradlePluginExt: GradlePluginDevelopmentExtension


context(FluxoKmpConfContext)
private fun MavenPublication.setupJavadocTask(
project: Project,
private fun Project.setupJavadocTask(
config: FluxoPublicationConfig,
useDokka: Boolean,
): Any {
type: ConfigurationType? = null,
): NamedDomainObjectProvider<out Task> {
// Publish docs with each artifact.
// Dokka artifacts are pretty big, so use them only for release builds, not for snapshots.
if (useDokka && !config.isSnapshot) {
Expand All @@ -470,33 +490,36 @@ private fun MavenPublication.setupJavadocTask(
id = BuildConstants.DOKKA_PLUGIN_ID,
version = BuildConstants.DOKKA_PLUGIN_VERSION,
catalogPluginId = BuildConstants.DOKKA_PLUGIN_ALIAS,
project = project,
project = this,
)
if (result.applied) {
project.logger.l("setup Dokka publication")
return project.getOrCreateDokkaTask().also {
artifact(it)
}
logger.l("setup Dokka publication")
return getOrCreateDokkaTask(type)
}
} catch (e: Throwable) {
project.logger.w("Fallback to Javadoc due to Dokka setup error: $e", e)
logger.w("Fallback to Javadoc due to Dokka setup error: $e", e)
}
}
project.logger.l("setup Javadoc publication fallback")
return project.getOrCreateJavadocTask().also {
artifact(it)
}
logger.l("setup Javadoc publication fallback")
return getOrCreateJavadocTask()
}

private fun Project.getOrCreateDokkaTask(): NamedDomainObjectProvider<out Task> {
private fun Project.getOrCreateDokkaTask(
type: ConfigurationType?,
): NamedDomainObjectProvider<out Task> {
val tasks = tasks
val taskName = if (tasks.has(JAVADOC_TASK_NAME)) "dokkaHtmlJar" else JAVADOC_TASK_NAME
return tasks.namedOrNull(JAVADOC_TASK_NAME)
?: tasks.register<Jar>(taskName) {
configureJavadocTask()
description = "Assembles Kotlin docs with Dokka into a Javadoc jar"
// Collect all `DokkaTask` tasks
from(project.tasks.named("dokkaHtml"))
// Collect Dokka output
val dokkaTaskName = when (type) {
ConfigurationType.KOTLIN_MULTIPLATFORM -> "dokkaHtml"
// Use Javadoc-like format for all non-KMP projects
else -> "dokkaJavadoc"
}
from(project.tasks.named(dokkaTaskName))
}
}

Expand All @@ -516,13 +539,13 @@ private const val JAVADOC_TASK_NAME = "javadocJar"

private fun Project.registerSourceJarTask(sourcePaths: Any): NamedDomainObjectProvider<out Task> {
val taskName = "sourcesJar"
val provider = tasks.namedOrNull(taskName)
?: tasks.register<Jar>(taskName) {
from(sourcePaths)
group = LifecycleBasePlugin.BUILD_GROUP
description = "Assembles a project sources jar."
archiveClassifier.set("sources")
}
val existing = tasks.namedOrNull(taskName)
val provider = existing ?: tasks.register<Jar>(taskName) {
from(sourcePaths)
group = LifecycleBasePlugin.BUILD_GROUP
description = "Assembles a project sources jar."
archiveClassifier.set("sources")
}

// Gradle 8+ workaround
markAsMustRunAfterBuildConfigTasks(provider)
Expand Down

0 comments on commit 1b155cd

Please sign in to comment.