Gradle,shadowJar:在任务内部使用重定位

编程入门 行业动态 更新时间:2024-10-25 04:27:05
本文介绍了Gradle,shadowJar:在任务内部使用重定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下任务:

task myJar(type: Jar) { archiveName = 'myJar.jar' includeEmptyDirs = false destinationDir = rootProject.libsDir dependsOn compileJava manifest.attributes('Class-Path': '../lib/commons-lang-2.5.jar') into '/', { from compileJava.destinationDir include 'com/myCompany/project/util/order/**', 'com/myCompany/project/event/**', } }

,我想将所有类从com/myCompany/project/event/**移至com/myCompany/relocated/project/event/**(以便某些使用我的jar并具有com.myCompany.project的应用定义的.event包将避免任何可能的冲突)

and I would like to relocate all classes from com/myCompany/project/event/** to com/myCompany/relocated/project/event/** (so that some apps using my jar and having com.myCompany.project.event package defined will avoid any possible conflicts)

我发现可以使用影子插件完成此操作,并且尝试添加

I discovered that it can be done using shadow plugin and I tried to add

relocate 'com.myCompany.project.event.', 'com.myCompany.relocated.project.event.'

在此任务下,但似乎不起作用. 有人知道我应该在哪里添加这一行吗?

under this task but it doesn't seem to work. Does anybody know where I should add this line?

推荐答案

您可以通过在build.gradle中添加以下插件来实现此目的

You can achieve this by adding below plugin to your build.gradle

apply plugin: 'com.github.johnrengelman.shadow'

添加此插件后,将以下代码添加到您的build.gradle文件中

After adding this plugin add below code to your build.gradle file

shadowJar { relocate 'com.myCompany.project.event', 'com.myCompany.relocated.project.event' }

添加此代码后,为确保ShadowJar任务在构建之前运行,请在末尾添加此行

After adding this, to ensure your ShadowJar task runs before build, add this line at the end

assemble.dependsOn shadowJar

这将确保在gradle构建期间在组装/构建任务之前触发阴影jar任务.

This will ensure that shadow jar task is triggered before assemble/build task during gradle build.

在完成Gradle构建时,您应该看到所有软件包及其对应的依赖项已从"com.myCompany.project.event"重新定位为"com.myCompany.relocated.project.event".

On doing the Gradle build, you should see all your packages and their corresponding dependencies relocated from 'com.myCompany.project.event' to 'com.myCompany.relocated.project.event'.

有关更多信息,您可以参考 ShadowJarUserGuide

For more info you can refer to ShadowJarUserGuide

更多推荐

Gradle,shadowJar:在任务内部使用重定位

本文发布于:2023-11-12 01:35:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Gradle   shadowJar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!