Skip to content

Commit

Permalink
Fix compileOnly dependencies (#28)
Browse files Browse the repository at this point in the history
* Update Gradle

* Fix compileOnly dependencies
  • Loading branch information
natario1 authored Dec 13, 2024
1 parent acfa789 commit e88c8e4
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pluginManagement {

// build.gradle.kts of deployable modules
plugins {
id("io.deepmedia.tools.deployer") version "0.15.0"
id("io.deepmedia.tools.deployer") version "0.16.0"
}
```

Expand Down
15 changes: 7 additions & 8 deletions deployer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
plugins {
`kotlin-dsl`
`java-gradle-plugin`
id("io.deepmedia.tools.deployer") version "0.14.0"
id("io.deepmedia.tools.deployer") version "0.15.0"
kotlin("plugin.serialization") version "1.9.23"
id("org.jetbrains.dokka") version "1.9.20"
}

dependencies {
compileOnly("com.android.tools.build:gradle:8.1.1")
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")

// api("org.jetbrains.dokka:dokka-gradle-plugin:1.8.20")

implementation("io.ktor:ktor-client-core:2.3.11")
implementation("io.ktor:ktor-client-cio:2.3.11")
implementation("io.ktor:ktor-client-content-negotiation:2.3.11")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.11")
implementation("io.ktor:ktor-client-core:2.3.13")
implementation("io.ktor:ktor-client-cio:2.3.13")
implementation("io.ktor:ktor-client-content-negotiation:2.3.13")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.13")
}

// To publish the plugin itself...
Expand All @@ -33,7 +32,7 @@ gradlePlugin {
}

group = "io.deepmedia.tools.deployer"
version = "0.15.0" // on change, update README
version = "0.16.0" // on change, update README

val javadocs = tasks.register<Jar>("dokkaJavadocJar") {
dependsOn(tasks.dokkaJavadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ internal class GradlePluginInference : Inference {

private fun inferComponents(project: Project, spec: DeploySpec, gradlePlugins: GradlePluginDevelopmentExtension, create: (Component.() -> Unit) -> Component) {
val mainComponent = create {
/* if (project.isKotlinProject) {
val kotlin = project.kotlinExtension as KotlinSingleTargetExtension<*>
fromKotlinTarget(kotlin.target as KotlinOnlyTarget<*>)
} else { */
fromMavenPublication("pluginMaven", clone = true)
packaging.set("jar")
// }
fromMavenPublication("pluginMaven", clone = true)
packaging.set("jar")
}
gradlePlugins.plugins.all {
create {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,6 @@ open class Component @Inject constructor(private val objects: ObjectFactory) {
docs.set(Artifacts.Entry.Promise { it.makeEmptyDocsJar })
}

// private val fallbackSources: Property<Project.() -> TaskProvider<Jar>> = objects.property()
// private val fallbackDocs: Property<Project.() -> TaskProvider<Jar>> = objects.property()
// fun emptySources() { fallbackSources.set { makeEmptySourcesJar } }
// fun kotlinSources() { fallbackSources.set { makeKotlinSourcesJar } }
// fun javaSources() { fallbackSources.set { makeJavaSourcesJar } }
// fun emptyDocs() { fallbackDocs.set { makeEmptyDocsJar } }
/* internal fun resolveSources(project: Project): Artifacts.Entry? {
val fallback = fallbackSources.map { project.it() }
.map { taskProvider -> Artifacts.Entry(taskProvider, taskProvider) }
// val fallback = fallbackSources.map { project.makeSourcesJar(spec, this, project.it()) }
return sources.orElse(fallback).orNull
}
internal fun resolveDocs(project: Project): Artifacts.Entry? {
val fallback = fallbackSources.map { project.it() }
.map { taskProvider -> Artifacts.Entry(taskProvider, taskProvider) }
// val fallback = fallbackDocs.map { project.makeDocsJar(spec, this, project.it()) }
return docs.orElse(fallback).orNull
} */

val extras: Artifacts = objects.newInstance()

val groupId = objects.property<Transformer<String, String>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.domainObjectSet
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import org.gradle.kotlin.dsl.*
import javax.inject.Inject

open class ProjectInfo @Inject constructor(private val objects: ObjectFactory) : LicenseScope, DeveloperScope, ScmScope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import java.io.File
*
* We go the second route below, which is a bit tricky because we have to deal with [Any] types.
*
* [Artifacts.Entry.Resolved.artifactForMaven]: May be one of
* [Artifacts.Entry.Resolved.artifact]: May be one of
* - [org.gradle.api.artifacts.PublishArtifact]. Extension and classifier values are taken from the wrapped instance.
* - [org.gradle.api.tasks.bundling.AbstractArchiveTask]. Extension and classifier values are taken from the wrapped instance.
* - Anything that can be resolved to a [java.io.File] via the [org.gradle.api.Project.file] method.
Expand Down Expand Up @@ -79,9 +79,9 @@ internal fun Artifacts.Entry.Resolved.wrapped(project: Project, logger: Logger,
else -> when (val data = unwrappedArtifact) {
is PublishArtifact -> data.classifier to data.extension
is AbstractArchiveTask -> data.archiveClassifier.orNull to data.archiveExtension.get()
// NOTE: logic here is very weak, could at least check if last() seems to be a version number and if so,
// we can infer that this file has no classifier (that is, it's the main POM artifact)
else -> resolvedFile.nameWithoutExtension.split("-").last() to resolvedFile.extension
// There's no safe way to determine the classifier from the filename. If important, users should specify it
// and the artifact would be an Artifacts.Entry.Dictionary which is a few branches above.
else -> null to resolvedFile.extension
}
}

Expand Down
52 changes: 1 addition & 51 deletions deployer/src/main/kotlin/io/deepmedia/tools/deployer/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,24 @@

package io.deepmedia.tools.deployer

import com.android.build.gradle.LibraryPlugin
import org.gradle.api.InvalidUserCodeException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.component.SoftwareComponent
import org.gradle.api.internal.component.SoftwareComponentInternal
import org.gradle.api.internal.project.ProjectStateInternal
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.publish.maven.MavenArtifact
import org.gradle.api.publish.maven.MavenArtifactSet
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper

internal fun String.capitalized(): String {
return replaceFirstChar { it.uppercaseChar() }
}

private var _hasKotlinPluginClasspath: Boolean? = null

private var _hasAndroidPluginClasspath: Boolean? = null

internal val Project.hasKotlinPluginClasspath: Boolean get() {
if (_hasKotlinPluginClasspath == null) {
_hasKotlinPluginClasspath = runCatching {
Class.forName("org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension")
}.isSuccess
}
return _hasKotlinPluginClasspath!!
}

internal val Project.hasAndroidPluginClasspath: Boolean get() {
if (_hasAndroidPluginClasspath == null) {
_hasAndroidPluginClasspath = runCatching {
Class.forName("com.android.build.gradle.api.AndroidBasePlugin")
}.isSuccess
}
return _hasAndroidPluginClasspath!!
}

// internal val Project.isJavaProject get() = plugins.any { it is JavaBasePlugin }
// internal val Project.isGradlePluginProject get() = plugins.any { it is JavaGradlePluginPlugin }
// internal val Project.isKmpProject get() = hasKotlinPluginClasspath && plugins.any { it is KotlinMultiplatformPluginWrapper }

internal val Project.isAndroidLibraryProject get() = hasAndroidPluginClasspath && plugins.any { it is LibraryPlugin }

internal val Project.isKotlinProject get() = hasKotlinPluginClasspath && plugins.any { it is KotlinBasePluginWrapper }

// internal fun Project.whenJavaPluginApplied(block: () -> Unit) = whenPluginApplied<JavaBasePlugin>(block)
// internal fun Project.whenGradlePluginPluginApplied(block: () -> Unit) = whenPluginApplied<JavaGradlePluginPlugin>(block)
// internal fun Project.whenAndroidLibraryPluginApplied(block: () -> Unit) {
// if (hasAndroidPluginClasspath) whenPluginApplied<LibraryPlugin>(block)
// }
/* internal fun Project.whenKmpPluginApplied(block: () -> Unit) {
if (!hasKotlinPluginClasspath) return
whenPluginApplied<KotlinMultiplatformPluginWrapper>(block)
}
// Not the recommended way but the other approach - use plugin IDs - requires to know the ID and it's not
// clear if withId() is invoked when the plugin is applied manually or only in the plugin block
internal inline fun <reified P: Plugin<*>> Project.whenPluginApplied(crossinline block: () -> Unit) {
plugins.withType<P>().all { block() }
} */
internal val Project.isKotlinProject get() = plugins.any { it is KotlinBasePluginWrapper }

internal fun MavenArtifactSet.dump(): String {
return if (isEmpty()) "[]"
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip

0 comments on commit e88c8e4

Please sign in to comment.