JetBrains / intellij-platform-plugin-template

Template repository for creating plugins for IntelliJ Platform
Apache License 2.0
3.04k stars 614 forks source link

trying to add aar dependency instead of jar fails to build #399

Closed munl closed 1 year ago

munl commented 1 year ago

What happened?

I'm trying to create a Android plugin to create a template project. But the dependency block doesn't seem to accept aar libraries. Here is the error below:

Could not determine the dependencies of task ':prepareSandbox'.
> Could not resolve all files for configuration ':runtimeClasspath'.
   > Could not resolve androidx.core:core-ktx:1.10.1.
     Required by:
         project :
      > No matching variant of androidx.core:core-ktx:1.10.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'releaseVariantReleaseApiPublication' capability androidx.core:core-ktx:1.10.1 declares a library, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, with the library elements 'aar' and the consumer needed a component for use during runtime, packaged as a jar

here is my build.gradle.kts which in the dependency block I've included a android dependency:

import io.gitlab.arturbosch.detekt.Detekt
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    // Java support
    id("java")
    // Kotlin support
    id("org.jetbrains.kotlin.jvm") version "1.8.0"
    // gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
    id("org.jetbrains.intellij") version "1.13.3"
    // gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
    id("org.jetbrains.changelog") version "2.0.0"
    // detekt linter - read more: https://detekt.github.io/detekt/gradle.html
    id("io.gitlab.arturbosch.detekt") version "1.23.0-RC3"
}

val androidStudioPath: String by project
val androidStudioPathMacOS: String by project
// Import variables from gradle.properties file
val pluginGroup: String by project
// `pluginName_` variable ends with `_` because of the collision with Kotlin magic getter in the `intellij` closure.
// Read more about the issue: https://github.com/JetBrains/intellij-platform-plugin-template/issues/29
val pluginName_: String by project
val pluginVersion: String by project
val pluginSinceBuild: String by project

val platformCompilerVersion: String by project
val platformPlugins: String by project
val platformDownloadSources: String by project

group = pluginGroup
version = pluginVersion

// Configure project's dependencies
repositories {
    mavenCentral()
    google()
}

// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1")
    implementation(libs.androidxCore)
}

// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
    pluginName.set(pluginName_)
    localPath.set(if (Os.isFamily(Os.FAMILY_WINDOWS)) androidStudioPath else androidStudioPathMacOS)
    downloadSources.set(platformDownloadSources.toBoolean())
    updateSinceUntilBuild.set(true)
    // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
    plugins.set(platformPlugins.split(',').map(String::trim).filter(String::isNotEmpty))
}

// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
changelog {
    version.set( provider { pluginVersion } )
    groups.set( provider { emptyList() } )
}

// Configure detekt plugin.
// Read more: https://detekt.github.io/detekt/kotlindsl.html
detekt {
    config.setFrom("./detekt-config.yml")
    autoCorrect = true
}

project.gradle.startParameter.excludedTaskNames.add("buildSearchableOptions")
tasks {
    // Set the compatibility versions to 11
    withType<JavaCompile> {
        sourceCompatibility = "11"
        targetCompatibility = "11"
    }
    listOf("compileKotlin", "compileTestKotlin").forEach {
        getByName<KotlinCompile>(it) {
            kotlinOptions.jvmTarget = "11"
        }
    }
    patchPluginXml {
        version.set(provider { pluginVersion } )
        sinceBuild.set(provider { pluginSinceBuild } )
        pluginDescription.set(provider {
            File("./README.md").readText().lines().run {
                val start = "<!-- Plugin description -->"
                val end = "<!-- Plugin description end -->"

                if (!containsAll(listOf(start, end))) {
                    throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
                }
                subList(indexOf(start) + 1, indexOf(end))
            }.joinToString("\n")
                .run { markdownToHTML(this) }
        })
        // Get the latest available change notes from the changelog file
        changeNotes.set( provider {
            changelog.render(
                org.jetbrains.changelog.Changelog.OutputType.HTML)
        } )
    }

    instrumentCode {
        compilerVersion.set(provider { platformCompilerVersion })
    }

    publishPlugin {
        dependsOn("patchChangelog")
        token.set(provider { System.getenv("PUBLISH_TOKEN") })
        // pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
        // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
        // https://jetbrains.org/intellij/sdk/docs/tutorials/build_system/deployment.html#specifying-a-release-channel
        channels.set(provider {
            pluginVersion.split('-')
                .getOrElse(1) { "default" }
                .split('.')
        } )
    }
}

tasks.withType(Detekt::class).configureEach {
    reports {
        html.required.set(false)
        xml.required.set(false)
        txt.required.set(false)
    }
}

and here is the gradel.properties file:

# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html

androidStudioPath = c:\\android-studio\\
androidStudioPathMacOS = /Applications/Android Studio.app/Contents

pluginGroup = com.github.munl.templatetest
pluginName_ = templatetest
pluginRepositoryUrl = https://github.com/munl/templatetest
# SemVer format -> https://semver.org
pluginVersion = 1.11.0
pluginSinceBuild = 201.*

platformCompilerVersion = 221.6008.13
platformDownloadSources = true

platformPlugins = com.intellij.java, org.jetbrains.android, org.jetbrains.kotlin

# Opt-out flag for bundling Kotlin standard library.
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
kotlin.stdlib.default.dependency = false

the build.gradle.kts references my libs.version.toml file:

# libraries
annotations = "24.0.1"
androidxCoreVersion = "1.10.1"

# plugins
kotlin = "1.9.0"
changelog = "2.1.2"
gradleIntelliJPlugin = "1.15.0"
qodana = "0.1.13"
kover = "0.7.3"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
androidxCore = { group = "androidx.core", name = "core-ktx",  version.ref = "androidxCoreVersion"}

[plugins]
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
gradleIntelliJPlugin = { id = "org.jetbrains.intellij", version.ref = "gradleIntelliJPlugin" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" }

Relevant log output or stack trace

No response

Steps to reproduce

added implementation(libs.androidxCore) the the dependency block

Gradle IntelliJ Plugin version

1.11.0

Gradle version

8.2.1

Operating System

macOS

Link to build, i.e. failing GitHub Action job

No response

hsz commented 1 year ago

It's impossible to use aar dependencies in a non-Android project, just jar. See https://stackoverflow.com/questions/33533370/difference-between-aar-jar-dex-apk-in-android/33533665#33533665