2017-08-21 45 views
2

我正在尝试为Maven构建一个自定义报告插件,与mvn site一起使用。创建一个Maven报告插件

但我找不到任何有关如何继续进行更新的文档。

有关创建插件的官方文档提到了扩展org.apache.maven.plugin.AbstractMojo。但这是关于通常构建生命周期的“常规”插件。这不适用于site构建生命周期。

上有一个类似的问题SO(Writing a maven custom report plugin; how do I generate the html body or "middle" of my report?),它是指从2015年的文件,其中提到了AbstractMavenReport类而不是AbstractMojo类,但我找不到它的任何地方在我的项目需要进口。

我也看了一些最近报告插件的代码(changes插件在这里:http://svn.apache.org/viewvc/maven/plugins/tags/maven-changes-plugin-2.12.1/),但我找不到我在找什么。

是否至少有报告插件的原型?任何人都有这方面的经验?

谢谢! - 贝特朗更多

+0

这里没有很多文档。你能告诉我们你想要做什么样的插件吗?最好的事情就是你所做的。 Whatch现有插件的代码。 如果你告诉我们一些关于你想要做的事情,我们可以建议一个插件来观看代码。 –

+0

我正在尝试构建一个基于项目的某些源代码(用第三方编辑器的专有语言编写)生成参考指南的插件。像Javadoc,但有不同的输入和不同的语法。我实际上找到了我的答案(见下面的答案)。谢谢! –

回答

1

挖掘一下,我发现我的答案: http://maven.apache.org/shared/maven-reporting-impl/index.html

和工作例如: http://svn.apache.org/viewvc/maven/shared/tags/maven-reporting-impl-3.0.0/src/it/setup-reporting-plugin/

所以,基本上,你需要这在的pom.xml

<dependencies> 
    <dependency> 
     <groupId>org.apache.maven.reporting</groupId> 
     <artifactId>maven-reporting-impl</artifactId> 
     <version>@[email protected]</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.reporting</groupId> 
     <artifactId>maven-reporting-api</artifactId> 
     <version>3.0</version> 
    </dependency> 

    <!-- plugin API and plugin-tools --> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-plugin-api</artifactId> 
     <version>3.0.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.plugin-tools</groupId> 
     <artifactId>maven-plugin-annotations</artifactId> 
     <version>3.3</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.maven.shared</groupId> 
     <artifactId>maven-shared-utils</artifactId> 
     <version>3.2.0</version> 
    </dependency> 
    </dependencies> 

然后,你的主类必须扩展AbstractMavenReport

import java.util.Locale; 
import org.apache.maven.plugins.annotations.Mojo; 
import org.apache.maven.reporting.AbstractMavenReport; 
import org.apache.maven.reporting.MavenReportException; 

/** 
* Typical code to copy as a reporting plugin start: choose the goal name, then implement getOutputName(), 
* getName(Locale), getDescription(Locale) and of course executeReport(Locale). 
*/ 
@Mojo(name = "custom") 
public class CustomReport 
    extends AbstractMavenReport 
{ 
    public String getOutputName() 
    { 
     return "custom-report"; 
    } 

    public String getName(Locale locale) 
    { 
     return "Custom Maven Report"; 
    } 

    public String getDescription(Locale locale) 
    { 
     return "Custom Maven Report Description"; 
    } 

    @Override 
    protected void executeReport(Locale locale) 
     throws MavenReportException 
    { 
     // direct report generation using Doxia: compare with CustomReportRenderer to see the benefits of using 
     // ReportRenderer 
     getSink().head(); 
     getSink().title(); 
     getSink().text("Custom Report Title"); 
     getSink().title_(); 
     getSink().head_(); 

     getSink().body(); 

     getSink().section1(); 
     getSink().sectionTitle1(); 
     getSink().text("section"); 
     getSink().sectionTitle1_(); 

     getSink().text("Custom Maven Report content."); 
     getSink().section1_(); 

     getSink().body_(); 
    } 
} 

希望这将有助于Maven Reporting插件的未来开发者! ;-)

+1

仅供参考,我刚刚开始了一个官方的Maven介绍https://maven.apache.org/guides/plugin/guide-java-report-plugin-development.html,它将详细解释为什么它就像你描述的那样。帮助和反馈赞赏:) – hboutemy

+0

谢谢Hervé!我认为这对开发人员来说是最有帮助的!我们能帮你什么吗? –

+0

如果你可以在这个页面上提供拉请求,这将帮助我很多 – hboutemy