如何在目标执行期间调试第三方 mvn 插件?

huangapple go评论82阅读模式
英文:

How can I debug a third party mvn plugin during goal execution?

问题

我在我的代码中使用了以下插件:

<plugin>
    <groupId>external.atlassian.jgitflow</groupId>
    <artifactId>jgitflow-maven-plugin</artifactId>
    <version>1.0-m5.1</version>
    <configuration>
        <username>${bbuser}</username>
        <password>${bbpw}</password>
        <flowInitContext>
            <masterBranchName>master</masterBranchName>
            <developBranchName>develop</developBranchName>
            <featureBranchPrefix>SPRINT-</featureBranchPrefix>
            <releaseBranchPrefix>release-</releaseBranchPrefix>
            <hotfixBranchPrefix>hotfix-</hotfixBranchPrefix>
        </flowInitContext>
    </configuration>
</plugin>

要执行它,我执行以下命令:

mvn -e -X -B -Dbbuser=$env.GIT_USERNAME -Dbbpw=$env.GIT_PASSWORD -DnoDeploy=true -DnoReleaseBuild=true -DpushReleases=true jgitflow:release-start

这在本地运行正常,但在Jenkins中出现以下异常:

[ERROR] Failed to execute goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start (default-cli) on project steeringcockpit: Execution default-cli of goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start failed: String index out of range: -6 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start (default-cli) on project steeringcockpit: Execution default-cli of goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start failed: String index out of range: -6
...
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start failed: String index out of range: -6
...
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -6
...

我想以某种方式使用mvnDebug和Eclipse调试器调试插件的执行,以在本地设置断点来检查发生了什么。问题是,我不知道如何将插件的源代码附加到我的Eclipse环境中,甚至在本地存储库中找不到插件的源代码。

如果我能够在Jenkins内部调试它,那将非常棒。这种可能性存在吗?

英文:

I am using the following plugin in my code:

			&lt;plugin&gt;
        	&lt;groupId&gt;external.atlassian.jgitflow&lt;/groupId&gt;
        	&lt;artifactId&gt;jgitflow-maven-plugin&lt;/artifactId&gt;
        	&lt;version&gt;1.0-m5.1&lt;/version&gt;
    		&lt;configuration&gt;
				&lt;username&gt;${bbuser}&lt;/username&gt;
  				&lt;password&gt;${bbpw}&lt;/password&gt;
  					&lt;flowInitContext&gt;
     					&lt;masterBranchName&gt;master&lt;/masterBranchName&gt;
     					&lt;developBranchName&gt;develop&lt;/developBranchName&gt;
     					&lt;featureBranchPrefix&gt;SPRINT-&lt;/featureBranchPrefix&gt;
     					&lt;releaseBranchPrefix&gt;release-&lt;/releaseBranchPrefix&gt;
     					&lt;hotfixBranchPrefix&gt;hotfix-&lt;/hotfixBranchPrefix&gt;
   					&lt;/flowInitContext&gt;
 			&lt;/configuration&gt;
    	    &lt;/plugin&gt;

To execute it I do the following:

 mvn -e -X -B -Dbbuser=$env.GIT_USERNAME -Dbbpw=$env.GIT_PASSWORD -DnoDeploy=true -DnoReleaseBuild=true -DpushReleases=true jgitflow:release-start

This works locally but in Jenkins I get the following exception:

    [ERROR] Failed to execute goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start (default-cli) on project steeringcockpit: Execution default-cli of goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start failed: String index out of range: -6 -&gt; [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start (default-cli) on project steeringcockpit: Execution default-cli of goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start failed: String index out of range: -6
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start failed: String index out of range: -6
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	... 20 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -6
	at java.lang.String.substring(String.java:1931)
	at com.atlassian.jgitflow.core.util.GitHelper.localBranchExists(GitHelper.java:193)
	at com.atlassian.jgitflow.core.GitFlowConfiguration.hasMasterConfigured(GitFlowConfiguration.java:128)
	at com.atlassian.jgitflow.core.JGitFlowInitCommand.call(JGitFlowInitCommand.java:152)
	at com.atlassian.maven.plugins.jgitflow.provider.DefaultJGitFlowProvider.gitFlow(DefaultJGitFlowProvider.java:32)
	at com.atlassian.maven.plugins.jgitflow.manager.AbstractFlowReleaseManager.runPreflight(AbstractFlowReleaseManager.java:67)
	at com.atlassian.maven.plugins.jgitflow.manager.AbstractProductionBranchManager.getStartLabelAndRunPreflight(AbstractProductionBranchManager.java:50)
	at com.atlassian.maven.plugins.jgitflow.manager.DefaultFlowReleaseManager.start(DefaultFlowReleaseManager.java:45)
	at com.atlassian.maven.plugins.jgitflow.mojo.ReleaseStartMojo.execute(ReleaseStartMojo.java:113)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	... 21 more

I would like to debug the execution of the plugin somehow using mvnDebug and the Eclipse debugger to set a breakpoint at this line to check what is happening locally. The problem is I don't know how to attach the source of the plugin to my eclipse environment and I cannot even find the plugins source in my local repository.

It would be extra cool if I could debug it within jenkins. Is this possible?

答案1

得分: 1

以下是翻译好的内容:

源代码位于此处:
https://bitbucket.org/atlassian/jgit-flow/src/1.0-m5.1/ (适用于您的插件版本)

请将 jgit-flow 克隆/下载到本地机器上,将项目作为新项目在 Eclipse 中打开。现在您可以为插件代码设置断点。

为 Eclipse 中的本地主机配置远程调试,端口为 8000。

在单独的 IDE / 控制台上,在您的项目上运行 mvnDebug,当您看到类似以下内容时:

Preparing to execute Maven in debug mode
Listening for transport dt_socket at address: 8000

在 Eclipse 中启动带有打开的插件代码的调试会话。

英文:

Source code are there:
https://bitbucket.org/atlassian/jgit-flow/src/1.0-m5.1/ (for your plugin version)

Please clone/download jgit-flow to local machine, open project in your Eclipse as new one. Now you can set breakpoint for plugin code.

Prepare configuration for remote debugging in Eclipse for localhost at 8000 port.

In separate ide / console run mvnDebug on your project and when you see something like:

Preparing to execute Maven in debug mode
Listening for transport dt_socket at address: 8000

Start debug session in Eclipse with opened plugin code

huangapple
  • 本文由 发表于 2020年9月3日 21:15:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63724453.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定