【问题标题】:Why maven doesn't generate project reports?为什么maven不生成项目报告?
【发布时间】:2011-05-05 23:16:12
【问题描述】:

这是 Maven 3.0。我正在创建一个新项目:

mvn archetype:create

然后我正在创建一个文件site/site.xml

<project name="foo">
  <body>
    <menu name="Overview">
      <item name="Introduction" href="index.html" />
    </menu>
    <menu ref="reports" />
  </body>
</project>

然后我添加一个报告插件到pom.xml

<reporting>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-project-info-reports-plugin</artifactId>
      <version>2.1.1</version>
    </plugin>
  </plugins>
</reporting>

然后我运行mvn site,它显示"BUILD SUCCESS"。但我在项目站点中没有看到任何报告(报告菜单项不存在)。我做错了什么?

【问题讨论】:

    标签: java maven maven-3


    【解决方案1】:

    这个 pom 可以工作(即使你没有定义 site.xml 文件)

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>it.cucchiara</groupId>
        <artifactId>test</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>test</name>
        <url>http://maven.apache.org</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <reporting>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-project-info-reports-plugin</artifactId>
                    <version>2.1.1</version>
                </plugin>
            </plugins>
        </reporting>
    </project>
    

    【讨论】:

    • 不,它没有。我有 Maven 3.0,也许这是问题所在?
    • 如果您使用的是 Maven 3.0,我认为您需要使用更新的站点插件。
    【解决方案2】:

    Maven 3 报告is different

    [...]
    <build>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0-beta-2</version>
        <configuration>
          <reportPlugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-project-info-reports-plugin</artifactId>
              <version>2.2</version>
              <reports>
                <report>cim</report>
                <report>issue-tracking</report>
              </reports>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-javadoc-plugin</artifactId>
              <version>2.2</version>
            </plugin>
          </reportPlugins>
        </configuration>
      </plugin>
    </build>
    [...]
    

    【讨论】:

    • 工作就像一个魅力,谢谢。我要补充一点,如果您希望报告生成 index.html 文件,您还必须将“索引”报告放在报告部分下。
    • 您提供的链接不再有效。你还有其他来源吗?编辑:我找到了链接:wakaleo.com/blog/site-generation-in-maven-3
    • @Scot 文档说reportPlugins 元素被标记为私有并且不应该被使用(还没有?):maven 3 info on maven-site-plugin site
    【解决方案3】:

    是的,maven 3 报告是不同的。提示:对于 maven 3,您可以使用版本 3.0-beta-2 中的 maven-site-plugin(站点插件版本 3.0-beta-3 在我的计算机上运行 maven 3.0-beta-3 时出错)。这将工作正常。但是对于报告:更改报告或更改日志我必须使用旧的报告方式。

    这里是我的 pom.xml 中有趣的部分。

            <build>
            :
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-site-plugin</artifactId>
              <version>3.0-beta-2</version>
              <executions>
                <execution>
                <id>createsite</id>
                <phase>package</phase>
                <goals>
                    <goal>site</goal>
                </goals>
                <configuration>
                    <reportPlugins>
                        <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>2.2</version>
                            <reportSets>
                            <reportSet>
                            <reports>
                              <report>dependencies</report>
                              <report>license</report>
                              <report>scm</report>
                              <report>project-team</report>
                            </reports>
                            </reportSet>
                            </reportSets>
                        </plugin>
                    </reportPlugins>
                </configuration>
                </execution>
             </executions>
          </plugin>
          :
        <build>
    
        <reporting>
          <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-changes-plugin</artifactId>
            <version>2.3</version>
            <reportSets>
            <reportSet>
            <reports>
              <report>changes-report</report>
            </reports>
            </reportSet>
            </reportSets>
            </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-changelog-plugin</artifactId>
              <version>2.2</version>
            </plugin>
            </plugins>
        </reporting>
    

    【讨论】:

    • 您好文森佐,感谢您的指正。我也遇到了你的问题,所以我尝试了很多变体。也许我在这里描述的变体只在 radom 有效。我应该删除我的答案吗?
    猜你喜欢
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 2014-05-15
    • 1970-01-01
    相关资源
    最近更新 更多