Skip to content

Commit 17a7519

Browse files
buenaflorromtsngetsentry-bot
authored
feat: add plugin support (#230)
* 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]>
1 parent 91222ef commit 17a7519

File tree

33 files changed

+1142
-16
lines changed

33 files changed

+1142
-16
lines changed

.craft.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ minVersion: 1.2.1
22
changelogPolicy: auto
33
targets:
44
- name: maven
5+
id: kmp
56
gradleCliPath: ./gradlew
67
mavenCliPath: scripts/mvnw
78
mavenSettingsPath: scripts/settings.xml
@@ -14,8 +15,19 @@ targets:
1415
kmp:
1516
rootDistDirRegex: /^(?!.*(?:jvm|android|ios|watchos|tvos|macos)).*$/
1617
appleDistDirRegex: /(ios|watchos|tvos|macos)/
18+
excludeNames: /sentry-kotlin-multiplatform-gradle-plugin.*$/
19+
- name: maven
20+
id: plugin
21+
gradleCliPath: ./gradlew
22+
mavenCliPath: scripts/mvnw
23+
mavenSettingsPath: scripts/settings.xml
24+
mavenRepoId: ossrh
25+
mavenRepoUrl: https://oss.sonatype.org/service/local/staging/deploy/maven2/
26+
android: false
27+
includeNames: /sentry-kotlin-multiplatform-gradle-plugin.*$/
1728
- name: github
1829
- name: registry
1930
sdks:
2031
maven:io.sentry:sentry-kotlin-multiplatform:
32+
# maven:io.sentry:sentry-kotlin-multiplatform-gradle-plugin:
2133

.github/workflows/analyze.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ jobs:
2626
distribution: temurin
2727

2828
- name: Analyze
29-
run: ./gradlew apiCheck detekt
29+
run:
30+
./gradlew apiCheck detekt spotlessCheck
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: "Plugin: sentry-kotlin-multiplatform"
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- release/**
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
runs-on: macos-latest-xlarge
16+
defaults:
17+
run:
18+
working-directory: sentry-kotlin-multiplatform-gradle-plugin
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: JDK setup
24+
uses: actions/setup-java@v3
25+
with:
26+
java-version: 17
27+
distribution: temurin
28+
29+
- name: Cached Konan
30+
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 #v3
31+
with:
32+
path: ~/.konan
33+
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
34+
restore-keys: ${{ runner.os }}-konan-
35+
36+
- name: Cached Gradle
37+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a
38+
39+
- name: Build
40+
run: |
41+
./gradlew build
42+
./gradlew koverXmlReport
43+
44+
- name: Upload coverage to Codecov
45+
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # pin@v4
46+
with:
47+
name: sentry-kotlin-multiplatform-gradle-plugin
48+
token: ${{ secrets.CODECOV_TOKEN }}
49+
50+
archive-distribution:
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: JDK setup
57+
uses: actions/setup-java@v3
58+
with:
59+
java-version: 17
60+
distribution: temurin
61+
62+
- name: Cached Gradle
63+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a
64+
65+
- name: DistZip
66+
run: |
67+
cd sentry-kotlin-multiplatform-gradle-plugin && ./gradlew distZip
68+
69+
- name: Archive packages
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: ${{ github.sha }}
73+
if-no-files-found: error
74+
path: |
75+
./*/build/distributions/*.zip

.github/workflows/kotlin-multiplatform.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ jobs:
9595
name: sentry-kotlin-multiplatform
9696
token: ${{ secrets.CODECOV_TOKEN }}
9797

98+
test-samples:
99+
runs-on: macos-latest-xlarge
100+
101+
steps:
102+
- uses: actions/checkout@v4
103+
104+
- name: JDK setup
105+
uses: actions/setup-java@v3
106+
with:
107+
java-version: 17
108+
distribution: temurin
109+
110+
- name: Cached Gradle
111+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a
112+
113+
- name: Test samples
114+
run: |
115+
./gradlew allTests -p sentry-samples
116+
98117
archive-distribution:
99118
runs-on: macos-latest-xlarge
100119

.run/iosApp-spm.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<component name="ProjectRunConfigurationManager">
2-
<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">
2+
<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">
33
<method v="2">
44
<option name="com.jetbrains.kmm.ios.BuildIOSAppTask" enabled="true" />
55
</method>

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

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

716
- Bump Kotlin version from v1.9.21 to v1.9.23 ([#250](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/250))

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ spotless {
7272

7373
kotlin {
7474
target("**/*.kt")
75+
targetExclude("**/generated/**/*.kt")
7576
ktlint()
7677
}
7778
kotlinGradle {
7879
target("**/*.kts")
80+
targetExclude("**/generated/**/*.kts")
7981
ktlint()
8082
}
8183
}
@@ -115,3 +117,8 @@ val detektProjectBaseline by tasks.registering(io.gitlab.arturbosch.detekt.Detek
115117
include("**/*.kt")
116118
detektExcludes()
117119
}
120+
121+
// Configure tasks so it is also run for the plugin
122+
tasks.getByName("detekt") {
123+
gradle.includedBuild("sentry-kotlin-multiplatform-gradle-plugin").task(":detekt")
124+
}

scripts/build-jvm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ -z "$1" ]; then
66
fi
77

88
PROJECT_NAME="$1"
9-
./gr
9+
1010
./gradlew "testDebugUnitTest" \
1111
"testReleaseUnitTest" \
1212
"publishAndroidReleasePublicationToMavenLocal" \

scripts/bump-version.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ OLD_VERSION="$1"
1212
NEW_VERSION="$2"
1313

1414
GRADLE_FILEPATH="gradle.properties"
15+
PLUGIN_GRADLE_FILEPATH="sentry-kotlin-multiplatform-gradle-plugin/gradle.properties"
1516

1617
# Replace `versionName` with the given version
1718
VERSION_NAME_PATTERN="versionName"
1819
perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $GRADLE_FILEPATH
20+
perl -pi -e "s/$VERSION_NAME_PATTERN=.*$/$VERSION_NAME_PATTERN=$NEW_VERSION/g" $PLUGIN_GRADLE_FILEPATH
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import com.vanniktech.maven.publish.MavenPublishPluginExtension
2+
import io.gitlab.arturbosch.detekt.Detekt
3+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
4+
5+
plugins {
6+
alias(libs.plugins.kotlin)
7+
alias(libs.plugins.detekt)
8+
`java-gradle-plugin`
9+
alias(libs.plugins.vanniktech.publish)
10+
id("distribution")
11+
alias(libs.plugins.buildConfig)
12+
alias(libs.plugins.kover)
13+
}
14+
15+
version = property("versionName").toString()
16+
17+
group = property("group").toString()
18+
19+
dependencies {
20+
compileOnly(kotlin("stdlib"))
21+
compileOnly(gradleApi())
22+
compileOnly(kotlin("gradle-plugin"))
23+
24+
testImplementation(kotlin("gradle-plugin"))
25+
testImplementation(libs.junit)
26+
testImplementation(libs.junit.params)
27+
testImplementation(libs.mockk)
28+
}
29+
30+
tasks.test {
31+
useJUnitPlatform()
32+
}
33+
34+
java {
35+
sourceCompatibility = JavaVersion.VERSION_11
36+
targetCompatibility = JavaVersion.VERSION_11
37+
}
38+
39+
tasks.withType<KotlinCompile> { kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() } }
40+
41+
gradlePlugin {
42+
plugins {
43+
create(property("id").toString()) {
44+
id = property("id").toString()
45+
implementationClass = property("implementationClass").toString()
46+
}
47+
}
48+
}
49+
50+
val publish = extensions.getByType(MavenPublishPluginExtension::class.java)
51+
// signing is done when uploading files to MC
52+
// via gpg:sign-and-deploy-file (release.kts)
53+
publish.releaseSigningEnabled = false
54+
55+
tasks.named("distZip").configure {
56+
dependsOn("publishToMavenLocal")
57+
this.doLast {
58+
val distributionFilePath =
59+
"${project.layout.buildDirectory.asFile.get().path}${sep}distributions${sep}${project.name}-${project.version}.zip"
60+
val file = File(distributionFilePath)
61+
if (!file.exists()) {
62+
throw IllegalStateException("Distribution file: $distributionFilePath does not exist")
63+
}
64+
if (file.length() == 0L) {
65+
throw IllegalStateException("Distribution file: $distributionFilePath is empty")
66+
}
67+
}
68+
}
69+
70+
val sep = File.separator
71+
72+
distributions {
73+
main {
74+
contents {
75+
from("build${sep}libs")
76+
from("build${sep}publications${sep}maven")
77+
}
78+
}
79+
}
80+
81+
buildConfig {
82+
useKotlinOutput()
83+
packageName("io.sentry")
84+
className("BuildConfig")
85+
86+
buildConfigField(
87+
"String",
88+
"SentryCocoaVersion",
89+
provider { "\"${project.property("sentryCocoaVersion")}\"" }
90+
)
91+
}
92+
93+
detekt { config.setFrom(rootProject.files("../config/detekt/detekt.yml")) }
94+
95+
tasks.withType<Detekt>().configureEach {
96+
reports {
97+
html.required.set(true)
98+
html.outputLocation.set(file("build/reports/detekt.html"))
99+
}
100+
}

0 commit comments

Comments
 (0)