Skip to content

Commit

Permalink
Merge pull request #283 from Burtan/kmp_support
Browse files Browse the repository at this point in the history
Resolve KMP artifact errors
  • Loading branch information
jk1 authored Apr 12, 2024
2 parents b70134a + 9a5f35e commit e188ed0
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ResolvedArtifact

import java.util.concurrent.atomic.AtomicInteger
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging

class CachingArtifactResolver {

private static Logger LOGGER = Logging.getLogger(CachingArtifactResolver.class)
private Map<Map<String, String>, Collection<ResolvedArtifact>> cache = new HashMap<>()
private Project project

Expand Down Expand Up @@ -52,6 +53,9 @@ class CachingArtifactResolver {
}
}
return artifacts
} catch (Throwable ignored) {
LOGGER.info("Could not resolve $spec.group:$spec.name:$spec.version. It will be skipped.")
return null
} finally {
project.configurations.remove(config)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ package com.github.jk1.license.reader
import com.github.jk1.license.AbstractGradleRunnerFunctionalSpec
import org.gradle.testkit.runner.TaskOutcome

import static com.github.jk1.license.reader.ProjectReaderFuncSpec.removeDevelopers

class MultiProjectReaderFuncSpec extends AbstractGradleRunnerFunctionalSpec {

def setup() {
settingsGradle = new File(testProjectDir, "settings.gradle")
settingsGradle << """
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
"""

buildFile << """
plugins {
Expand Down Expand Up @@ -562,6 +569,110 @@ class MultiProjectReaderFuncSpec extends AbstractGradleRunnerFunctionalSpec {
configurationsGPath.name == ["mainConfig", "subConfig"]
}
/*
Test kotlin multiplatform project structure, including subproject reports and custom
output dirs
*/
def "Test Kotlin Multiplatform"() {
setup:
def properties = new File(testProjectDir, "gradle.properties")
properties << "android.useAndroidX = true"
newSubBuildFile("shared") << """
plugins {
id "com.android.library" version "8.1.3"
id "org.jetbrains.kotlin.multiplatform" version "1.9.20"
id "com.github.jk1.dependency-license-report"
}
configurations {
mainConfig
}
repositories {
mavenCentral()
google()
}
kotlin {
androidTarget()

sourceSets {
commonMain.dependencies {
api("io.ktor:ktor-client-core:2.3.6")
implementation("com.benasher44:uuid:0.7.0")
}

androidMain.dependencies {
implementation("app.cash.sqldelight:android-driver:2.0.0")
implementation("io.ktor:ktor-client-android:2.3.6")
}
}
}
android {
namespace "com.example.shared"
compileSdk 34
defaultConfig {
minSdk 26
}
}
// shared folder reports are useful for iOS license reports
licenseReport {
// test relative paths
outputDir = "sharedBuild/reports/license-test/"
renderers = [new com.github.jk1.license.render.JsonReportRenderer()]
configurations = [
"commonMainCompileOnlyDependenciesMetadata",
"iosMainCompileOnlyDependenciesMetadata"
]

println("Output shared: " + outputDir)
}
"""
newSubBuildFile("android") << """
plugins {
id "com.android.application" version "8.1.3"
id "org.jetbrains.kotlin.android" version "1.9.20"
id "com.github.jk1.dependency-license-report"
}
configurations {
mainConfig
}
repositories {
mavenCentral()
google()
}
android {
namespace "com.example.android"
compileSdk 34
defaultConfig {
applicationId "com.example.android"
minSdk 26
targetSdk 34
}
dependencies {
implementation project(":shared")
}
}
licenseReport {
// test relative paths
outputDir = "androidBuild/reports/license-test/"
renderers = [new com.github.jk1.license.render.JsonReportRenderer()]
configurations = ["releaseRuntimeClasspath"]

println("Output android: " + outputDir)
}
"""
when:
def runResult = runGradleBuild()
then:
runResult.task(":android:generateLicenseReport").outcome == TaskOutcome.SUCCESS
runResult.task(":shared:generateLicenseReport").outcome == TaskOutcome.SUCCESS
runResult.task(":generateLicenseReport").outcome == TaskOutcome.SUCCESS
println(testProjectDir.list())
}
static void removeDevelopers(Map rawFile) {
rawFile.configurations*.dependencies.flatten().poms.flatten().each { it.remove("developers") }
}
Expand Down

0 comments on commit e188ed0

Please sign in to comment.