简体   繁体   English

如何调试第三方Gradle插件?

[英]How to debug a third-party Gradle plugin?

I'm trying to sign an Android AAR artifact using the gradle signing plugin . 我正在尝试使用gradle签名插件签署 Android AAR工件。 Unfortunately, I'm getting a rather unhelpful NullPointerException in the process: 不幸的是,我在这个过程中遇到了一个相当无用的NullPointerException

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':library:signArchives'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':library:signArchives'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        [...snip...]
        at org.gradle.launcher.Main.main(Main.java:37)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.lang.NullPointerException
        at org.bouncycastle.openpgp.PGPSignatureGenerator.initSign(Unknown Source)
        at org.bouncycastle.openpgp.PGPSignatureGenerator.initSign(Unknown Source)
        at org.bouncycastle.openpgp.PGPSignatureGenerator$initSign.call(Unknown Source)
        at org.gradle.plugins.signing.signatory.pgp.PgpSignatory.createSignatureGenerator(PgpSignatory.groovy:54)
        at org.gradle.plugins.signing.signatory.pgp.PgpSignatory.sign(PgpSignatory.groovy:64)
        [...snip...]
        ... 52 more


BUILD FAILED

What's the easiest way to debug this exception? 调试此异常的最简单方法是什么? Is there a way to attach a debugger to gradle? 有没有办法将调试器附加到gradle? Can I build the signing plugin, insert some logging statements and tell my build to pick up my custom version instead of the one it ships with? 我可以构建签名插件,插入一些日志记录语句并告诉我的构建版本来获取我的自定义版本而不是它附带的版本吗?

According to a thread in the gradle forums there is a somewhat secret org.gradle.debug -flag that allows you to attach a debugger. 根据gradle论坛中的一个帖子,有一个秘密的org.gradle.debug -flag可以让你附加一个调试器。

gradle someTask --no-daemon -Dorg.gradle.debug=true

For the hotfixing/custom-plugin it should be enough to put your copied & modified plugin in rootProjectDir/buildSrc/src/main/groovy . 对于hotfixing / custom-plugin,它应该足以将你复制和修改的插件放在rootProjectDir/buildSrc/src/main/groovy You can read more about writing a custom plugin on the Gradle site . 您可以阅读有关在Gradle站点上编写自定义插件的更多信息。

This is how I did it using IntelliJ - Android Studio is based on IntelliJ so it should be the same, and other IDEs should be similar: 这就是我使用IntelliJ做的方式 - Android Studio基于IntelliJ所以它应该是相同的,其他IDE应该是相似的:

Download the correct version of the source code of the buggy Gradle plugin, or clone/access its version control repository and check out the relevant branch or tag corresponding to the version of the buggy Gradle plugin you are using. 下载错误Gradle插件的源代码的正确版本,或克隆/访问其版本控制存储库,并检查与您正在使用的错误Gradle插件版本对应的相关分支或标记。 Import the code into IntelliJ by using File -> New project from existing sources. 使用文件 - >现有源中的新项目将代码导入IntelliJ。 Then run, at the command line: 然后在命令行运行:

./gradlew someTask -Dorg.gradle.debug=true --no-daemon

and create a new remote debugging connection using port 5005, set your initial breakpoint, and start it. 并使用端口5005创建一个新的远程调试连接,设置您的初始断点,然后启动它。

Alternatively, you can use the Gradle daemon by instead doing ./gradlew -Dorg.gradle.jvmargs=" standard JVM debugging arguments " , and this way you can use any debugging port you like, but I have not tested this. 或者,您可以使用Gradle守护程序代替./gradlew -Dorg.gradle.jvmargs=" 标准JVM调试参数 " ,这样您就可以使用任何您喜欢的调试端口,但我还没有对此进行测试。 For example: 例如:

./gradlew \
  -Dorg.gradle.jvmargs="-agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=y" \
  someTask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调试第三方 Intellij IDEA 插件? - How to debug third-party Intellij IDEA plugin? 控制 gradle 插件中使用的第三方库的日志输出 - Control logging output from third-party libraries used in a gradle plugin 使用Gradle将所有创建的和第三方jar复制到一个文件夹中 - Copy all created & third-party jars into a single folder with Gradle 是否可以在第三方Android应用程序中调试类? - Is it possible to debug classes in a third-party Android application? 如何使用p2-maven-plugin有效管理第三方依赖? - How to efficiently manage third-party dependencies with p2-maven-plugin? Android / PhoneGap:在插件开发中使用第三方库 - Android/PhoneGap: Using third-party libraries in plugin-development 无法在 build.gradle 以外的 gradle 文件中导入第三方类 - Could not import third-party class in gradle file other than build.gradle Gradle Compile & Execute the Single Java Class with third-party jar dependencies using Gradle `buildscript` - Gradle Compile & Execute the Single Java Class with third-party jar dependencies using Gradle `buildscript` 如何在私有静态方法中模拟第三方类? - How to mock a third-party class in private static method? 如何在第三方Maven依赖项中使用执行切入点? - How to use execution pointcut with third-party maven dependency?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM