Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Bundling does not support more than one compileSourceRoots & can fail for Kotlin only projects #70

Open
btpnlsl opened this issue Apr 2, 2024 · 3 comments
Labels
bug Something isn't working Platform: Java

Comments

@btpnlsl
Copy link

btpnlsl commented Apr 2, 2024

Maven Version

3.9.6

Version

0.0.7

Sentry SDK Version

7.6.0

Steps to Reproduce

I have a parent POM file which is used in multiple projects, some of which are mixed Java/Kotlin, others which are Kotlin only and others which have multiple root sources. The parent POM uses org.codehaus.mojo:build-helper-maven-plugin to add the src/main/kotlin directory to the list of directories which might contain sources which should be compiled. Typically the compile sources roots will contain both src/main/java and src/main/kotlin, but can contain other source roots for code generated by Open API generator.

I believe that the issue is in [UploadSourceBundleMojo.java](https://github.com/getsentry/sentry-maven-plugin/blob/7798467289097c3882a36c794497311eb61887da/src/main/java/io/sentry/UploadSourceBundleMojo.java#L109C1-L112C10) where the code is always picking the first entry in the list of possible source roots.

If the compileSourceRoots contains multiple entries and the first one actually has code in it (say for a mixed Java/Kotlin project) this works ok. But if the project only has code in src/main/kotlin then source bundling will fail. If the project has additional code in another source root (say from OpenAPI generated clients or services) this code will not be bundled and uploaded.

How is this supposed to work for projects which have multiple source roots, or for projects which do not use the 1st source root as described?

Expected Result

The plugin should support bundling source from multiple roots.

Actual Result

For projects which have multiple compile source roots (like src/main/java and src/main/kotlin) but only have code in the second source root, the build will fail like so:

[INFO] [WARNING] There's more than one source root, using /build/target/checkout/kotlin-only-service/src/main/java
.....
[INFO]   DEBUG   2024-04-02 21:30:13.385720499 +00:00 body: {"url":"organizations/omnidian/chunk-upload/","chunkSize":8388608,"chunksPerRequest":64,"maxFileSize":2147483648,"maxRequestSize":33554432,"concurrency":8,"hashAlgorithm":"sha1","compression":["gzip"],"accept":["debug_files","release_files","pdbs","sources","bcsymbolmaps","il2cpp","portablepdbs","artifact_bundles","artifact_bundles_v2"]}
[INFO] error: Given path does not exist: /build/target/checkout/kotlin-only-service/src/main/java

For projects which have multiple compile source roots which have code in the, only the code in the first directory will be bundled.

@btpnlsl btpnlsl added bug Something isn't working Platform: Java labels Apr 2, 2024
@adinauer
Copy link
Member

adinauer commented Apr 3, 2024

Thanks for opening this issue @btpnlsl. We can look into supporting multiple source roots but I can't give an ETA.

Only supporting once was a shortcut we took to get the feature shipped more quickly. I think we have to copy all sources into a single directory then pass that single directory to sentry-cli for bundling. We do the same thing on our Gradle plugin (see https://github.com/getsentry/sentry-android-gradle-plugin/blob/2c6afbed6eeca00a5f9305cde0d06d95f2bd4d9a/plugin-build/src/main/kotlin/io/sentry/android/gradle/sourcecontext/CollectSourcesTask.kt).

We should probably also add a config option to specify additional directories for sources (https://github.com/getsentry/sentry-android-gradle-plugin/blob/main/plugin-build/src/main/kotlin/io/sentry/android/gradle/extensions/SentryPluginExtension.kt).

@btpnlsl
Copy link
Author

btpnlsl commented Apr 3, 2024

Thanks @adinauer. Do you have a link to any more documentation for how source bundling should be done for projects which include multiple modules?

For example, we have a Sentry project service-A which receives error reports from a deployable web service. The maven build for service-A also has dependencies on some common modules, say common-1, common-2, & common-3.

How would we bundle the source for those common modules so that Sentry can use it to figure out relevant stack info for uncaught exceptions / logs?

@adinauer
Copy link
Member

adinauer commented Apr 4, 2024

Not yet, can you try adding the sentry maven plugin to each module? In theory it should just generate a debug-meta.properties file in each module which the Java SDK should be able to detect automatically. I haven't tested this yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Platform: Java
Projects
None yet
Development

No branches or pull requests

2 participants