-
-
Notifications
You must be signed in to change notification settings - Fork 24
Shadow kotlinx.serialization to the compiler plugin #54
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,10 +13,15 @@ | |
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| import org.gradle.api.publish.maven.MavenPublication | ||
| import org.gradle.jvm.tasks.Jar | ||
|
|
||
| plugins { | ||
| kotlin("jvm") | ||
| alias(libs.plugins.kotlin.serialization) | ||
| alias(libs.plugins.shadow) | ||
| alias(libs.plugins.nexus.plugin) | ||
| `maven-publish` | ||
| } | ||
|
|
||
| kotlin { | ||
|
|
@@ -47,4 +52,38 @@ dependencies { | |
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
|
|
||
| // Configure shadowJar to embed kotlinx.serialization | ||
| tasks.shadowJar { | ||
| archiveClassifier.set("all") // Use a classifier to avoid conflict with jar task | ||
|
|
||
| // Merge all runtime dependencies (including kotlinx-serialization) | ||
| // By default, shadow excludes nothing, so we need to explicitly configure | ||
| configurations = listOf(project.configurations.runtimeClasspath.get()) | ||
|
|
||
| // Don't relocate - K/Native compiler needs original package names | ||
| // relocate("kotlinx.serialization", "...") | ||
|
|
||
| // Exclude unnecessary files | ||
| exclude("META-INF/maven/**") | ||
| exclude("META-INF/*.SF") | ||
| exclude("META-INF/*.DSA") | ||
| exclude("META-INF/*.RSA") | ||
| } | ||
|
|
||
| // Make jar task produce the shadowJar content | ||
| tasks.named<Jar>("jar") { | ||
| dependsOn(tasks.shadowJar) | ||
| // Copy shadowJar content after jar is built | ||
| doLast { | ||
| val shadowTask = tasks.shadowJar.get() | ||
| val shadowJarFile = shadowTask.archiveFile.get().asFile | ||
| val jarFile = archiveFile.get().asFile | ||
|
|
||
| if (shadowJarFile.exists()) { | ||
| shadowJarFile.copyTo(jarFile, overwrite = true) | ||
| logger.lifecycle("Replaced ${jarFile.name} with shadowJar content") | ||
| } | ||
| } | ||
|
Comment on lines
70
to
81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jar replacement logic is fragile and non-standard. Using Consider these alternatives:
Do you have a specific reason for the current approach, or would you prefer to refactor this to use standard Gradle patterns? 🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.