Skip to content

Commit

Permalink
feat: add plugin support (#230)
Browse files Browse the repository at this point in the history
* Add raw working impl

* Update

* Update

* Update

* Update

* Update plugin

* Update

* Update

* Update

* Update

* Update

* Updatee

* Update doc

* Update docs

* Remove print

* Update

* Update

* Update comment

* Update

* Update

* Update

* Format

* Format

* Update plugin-build/plugin/src/main/java/io/sentry/kotlin/multiplatform/gradle/plugin/SentryPlugin.kt

Co-authored-by: Roman Zavarnitsyn <[email protected]>

* check if isStatic in linking

* Update plugin build dir name and ID

* Add deps only with compileOnly

* Update

* Updaet

* Include gradle plugin version bump

* Update project name

* Use buildconfig

* Remove todo

* Change sentry extension name to sentryKmp

* Set androidNative to unsupported targets

* add symlinks

* Update

* Update

* Update'

* Update

* Add CI

* Add to craft

* Remove package.resolved

* Format

* Update

* Update changelog

* Enable cocoapods sample

* Update

* Remove podspec from spm sample

* Remove

* Format

* Update

* Fix deps

* update

* update

* Update Changelog

* add ~> to version

* Add derived data value source for caching

* Run test during ci

* Update

* formatting{

* format

* Skip apple specific configs if there are not apple targets

* Fix tests

* Update CI and skip linker and cocoapods if not macOS host

* Format code

* update

* Update

* update

* Add compilation test through samples

* run allTests for every sample project

* Update CHANGELOG.md

* Upload codecov report

* Default working directory

* Use kover 0.7.3

* Update

* Update

* Update

---------

Co-authored-by: Roman Zavarnitsyn <[email protected]>
Co-authored-by: Sentry Github Bot <[email protected]>
  • Loading branch information
3 people committed Aug 5, 2024
1 parent 91222ef commit 17a7519
Show file tree
Hide file tree
Showing 33 changed files with 1,142 additions and 16 deletions.
12 changes: 12 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ minVersion: 1.2.1
changelogPolicy: auto
targets:
- name: maven
id: kmp
gradleCliPath: ./gradlew
mavenCliPath: scripts/mvnw
mavenSettingsPath: scripts/settings.xml
Expand All @@ -14,8 +15,19 @@ targets:
kmp:
rootDistDirRegex: /^(?!.*(?:jvm|android|ios|watchos|tvos|macos)).*$/
appleDistDirRegex: /(ios|watchos|tvos|macos)/
excludeNames: /sentry-kotlin-multiplatform-gradle-plugin.*$/
- name: maven
id: plugin
gradleCliPath: ./gradlew
mavenCliPath: scripts/mvnw
mavenSettingsPath: scripts/settings.xml
mavenRepoId: ossrh
mavenRepoUrl: https://oss.sonatype.org/service/local/staging/deploy/maven2/
android: false
includeNames: /sentry-kotlin-multiplatform-gradle-plugin.*$/
- name: github
- name: registry
sdks:
maven:io.sentry:sentry-kotlin-multiplatform:
# maven:io.sentry:sentry-kotlin-multiplatform-gradle-plugin:

3 changes: 2 additions & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ jobs:
distribution: temurin

- name: Analyze
run: ./gradlew apiCheck detekt
run:
./gradlew apiCheck detekt spotlessCheck
75 changes: 75 additions & 0 deletions .github/workflows/kotlin-multiplatform-gradle-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: "Plugin: sentry-kotlin-multiplatform"
on:
push:
branches:
- main
- release/**
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: macos-latest-xlarge
defaults:
run:
working-directory: sentry-kotlin-multiplatform-gradle-plugin

steps:
- uses: actions/checkout@v4

- name: JDK setup
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin

- name: Cached Konan
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 #v3
with:
path: ~/.konan
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-konan-

- name: Cached Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a

- name: Build
run: |
./gradlew build
./gradlew koverXmlReport
- name: Upload coverage to Codecov
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@v4
with:
name: sentry-kotlin-multiplatform-gradle-plugin
token: ${{ secrets.CODECOV_TOKEN }}

archive-distribution:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: JDK setup
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin

- name: Cached Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a

- name: DistZip
run: |
cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew distZip
- name: Archive packages
uses: actions/upload-artifact@v3
with:
name: ${{ github.sha }}
if-no-files-found: error
path: |
./*/build/distributions/*.zip
19 changes: 19 additions & 0 deletions .github/workflows/kotlin-multiplatform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ jobs:
name: sentry-kotlin-multiplatform
token: ${{ secrets.CODECOV_TOKEN }}

test-samples:
runs-on: macos-latest-xlarge

steps:
- uses: actions/checkout@v4

- name: JDK setup
uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin

- name: Cached Gradle
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a

- name: Test samples
run: |
./gradlew allTests -p sentry-samples
archive-distribution:
runs-on: macos-latest-xlarge

Expand Down
2 changes: 1 addition & 1 deletion .run/iosApp-spm.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="iosApp-spm" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="27607109-90E2-4A98-8165-C0FF206F6E6D" XCODE_PROJECT="$PROJECT_DIR$/sentry-samples/kmp-app-spm/iosApp.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosApp">
<configuration default="false" name="iosApp-spm" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="EA7F395B-4B34-4EEA-8D00-85297FF4E3BD" XCODE_PROJECT="$PROJECT_DIR$/sentry-samples/kmp-app-spm/iosApp.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosApp">
<method v="2">
<option name="com.jetbrains.kmm.ios.BuildIOSAppTask" enabled="true" />
</method>
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

### Features

- New Sentry KMP Gradle plugin ([#230](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/230))
- Install via `plugins { id("io.sentry.kotlin.multiplatform.gradle") version "{version}" }`
- Enables auto installing of the KMP SDK to commonMain (if all targets are supported)
- Enables auto installing of the required Sentry Cocoa SDK with Cocoapods (if Cocoapods plugin is enabled)
- Configures linking for SPM (needed if you want to compile a dynamic framework)
- Configure via the `sentryKmp` configuration block in your build file

### Dependencies

- Bump Kotlin version from v1.9.21 to v1.9.23 ([#250](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/250))
Expand Down
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ spotless {

kotlin {
target("**/*.kt")
targetExclude("**/generated/**/*.kt")
ktlint()
}
kotlinGradle {
target("**/*.kts")
targetExclude("**/generated/**/*.kts")
ktlint()
}
}
Expand Down Expand Up @@ -115,3 +117,8 @@ val detektProjectBaseline by tasks.registering(io.gitlab.arturbosch.detekt.Detek
include("**/*.kt")
detektExcludes()
}

// Configure tasks so it is also run for the plugin
tasks.getByName("detekt") {
gradle.includedBuild("sentry-kotlin-multiplatform-gradle-plugin").task(":detekt")
}
2 changes: 1 addition & 1 deletion scripts/build-jvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "$1" ]; then
fi

PROJECT_NAME="$1"
./gr

./gradlew "testDebugUnitTest" \
"testReleaseUnitTest" \
"publishAndroidReleasePublicationToMavenLocal" \
Expand Down
2 changes: 2 additions & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ OLD_VERSION="$1"
NEW_VERSION="$2"

GRADLE_FILEPATH="gradle.properties"
PLUGIN_GRADLE_FILEPATH="sentry-kotlin-multiplatform-gradle-plugin/gradle.properties"

# Replace `versionName` with the given version
VERSION_NAME_PATTERN="versionName"
perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $GRADLE_FILEPATH
perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $PLUGIN_GRADLE_FILEPATH
100 changes: 100 additions & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import com.vanniktech.maven.publish.MavenPublishPluginExtension
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.kotlin)
alias(libs.plugins.detekt)
`java-gradle-plugin`
alias(libs.plugins.vanniktech.publish)
id("distribution")
alias(libs.plugins.buildConfig)
alias(libs.plugins.kover)
}

version = property("versionName").toString()

group = property("group").toString()

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly(gradleApi())
compileOnly(kotlin("gradle-plugin"))

testImplementation(kotlin("gradle-plugin"))
testImplementation(libs.junit)
testImplementation(libs.junit.params)
testImplementation(libs.mockk)
}

tasks.test {
useJUnitPlatform()
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType<KotlinCompile> { kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() } }

gradlePlugin {
plugins {
create(property("id").toString()) {
id = property("id").toString()
implementationClass = property("implementationClass").toString()
}
}
}

val publish = extensions.getByType(MavenPublishPluginExtension::class.java)
// signing is done when uploading files to MC
// via gpg:sign-and-deploy-file (release.kts)
publish.releaseSigningEnabled = false

tasks.named("distZip").configure {
dependsOn("publishToMavenLocal")
this.doLast {
val distributionFilePath =
"${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip"
val file = File(distributionFilePath)
if (!file.exists()) {
throw IllegalStateException("Distribution file: $distributionFilePath does not exist")
}
if (file.length() == 0L) {
throw IllegalStateException("Distribution file: $distributionFilePath is empty")
}
}
}

val sep = File.separator

distributions {
main {
contents {
from("build${sep}libs")
from("build${sep}publications${sep}maven")
}
}
}

buildConfig {
useKotlinOutput()
packageName("io.sentry")
className("BuildConfig")

buildConfigField(
"String",
"SentryCocoaVersion",
provider { "\"${project.property("sentryCocoaVersion")}\"" }
)
}

detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) }

tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
html.outputLocation.set(file("build/reports/detekt.html"))
}
}
6 changes: 6 additions & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id=io.sentry.kotlin.multiplatform.gradle
implementationClass=io.sentry.kotlin.multiplatform.gradle.SentryPlugin
versionName=0.7.1
group=io.sentry
# TODO: Update update-cocoa.sh so the cocoa version is auto updated as well
sentryCocoaVersion=8.26.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[versions]
detekt = "1.23.6"
kotlin = "1.9.23"
pluginPublish = "1.2.1"
buildConfig = "5.3.5"
vanniktechPublish = "0.18.0"
kover = "0.7.3"

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt"}
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"}
pluginPublish = { id = "com.gradle.plugin-publish", version.ref = "pluginPublish"}
vanniktech-publish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechPublish"}
buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig"}
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover"}

[libraries]
junit = "org.junit.jupiter:junit-jupiter-api:5.10.3"
junit-params = "org.junit.jupiter:junit-jupiter-params:5.10.3"
mockk = "io.mockk:mockk:1.13.12"
1 change: 1 addition & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/gradle/wrapper
1 change: 1 addition & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/gradlew
1 change: 1 addition & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/gradlew.bat
15 changes: 15 additions & 0 deletions sentry-kotlin-multiplatform-gradle-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}

rootProject.name = "sentry-kotlin-multiplatform-gradle-plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.sentry.kotlin.multiplatform.gradle

import org.gradle.api.Project
import org.gradle.api.provider.Property
import javax.inject.Inject

@Suppress("UnnecessaryAbstractClass")
abstract class AutoInstallExtension @Inject constructor(project: Project) {
private val objects = project.objects

/**
* Enable auto-installation of the Sentry dependencies through [CocoapodsAutoInstallExtension]
* and [SourceSetAutoInstallExtension].
*
* Disabling this will prevent the plugin from auto installing any dependency.
*
* Defaults to true.
*/
val enabled: Property<Boolean> = objects.property(Boolean::class.java).convention(true)

val cocoapods: CocoapodsAutoInstallExtension =
objects.newInstance(CocoapodsAutoInstallExtension::class.java, project)

val commonMain: SourceSetAutoInstallExtension =
objects.newInstance(SourceSetAutoInstallExtension::class.java, project)
}
Loading

0 comments on commit 17a7519

Please sign in to comment.