首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用maven从groovydoc生成jar文件

用maven从groovydoc生成jar文件
EN

Stack Overflow用户
提问于 2012-11-12 20:05:40
回答 1查看 680关注 0票数 1

有没有办法生成在IDE中使用的jar文件(如IDEA、Eclipse等)?从maven内部生成的groovydoc?我目前正在使用这里描述的maven antrun插件从一个相当大的groovy项目中生成groovydoc:GroovyDoc as Maven Plugin

我可以通过手动将输出的文件打包到归档中来获得一个可用的jar文件,但我正在寻找一种集成的方式(即,使用maven),它也允许我将这些文件部署到存储库。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-12 21:12:05

如果您在帖子中使用了链接,那么groovydoc将在site阶段生成。

为了使用生成的groovydoc组装jar,您可以使用maven-assembly-plugin

我已经创建了一个src/main/assembly目录,其中添加了供maven-assembly-plugin使用的程序集描述符。

这是一个在site阶段和打包groovydoc jar时生成groovydoc的工作示例。

pom.xml

代码语言:javascript
复制
<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>com.stackoverflow.Q13343411</groupId>
    <artifactId>groovy</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>${project.artifactId}-${project.version}</name>

    <properties>
        <gmavenVersion>1.4</gmavenVersion>
        <gmavenProviderSelection>2.0</gmavenProviderSelection>
        <groovyVersion>2.0.0</groovyVersion>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>${groovyVersion}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <version>${gmavenVersion}</version>
                <configuration>
                    <providerSelection>${gmavenProviderSelection}</providerSelection>
                    <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
                    <source/>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <!-- Only used when doing java/groovy join builds
                                 OR, add the dependency to groovy-all again here in the plugin
                            -->
                            <goal>generateStubs</goal>
                            <goal>compile</goal>
                            <!-- Only used when doing java/groovy join builds
                                 OR, add the dependency to groovy-all again here in the plugin
                            -->
                            <goal>generateTestStubs</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-all</artifactId>
                        <version>${groovyVersion}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>groovydoc</id>
                        <phase>site</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <taskdef name="groovydoc"
                                         classname="org.codehaus.groovy.ant.Groovydoc"
                                         classpathref="maven.compile.classpath"
                                        />
                                <groovydoc destdir="${project.reporting.outputDirectory}/groovydoc"
                                           sourcepath="${basedir}/src/main/groovy" use="true"
                                           windowtitle="${project.name}"
                                           doctitle="${project.name}"
                                        >
                                    <link packages="java.,org.xml.,javax.,org.xml."
                                          href="http://download.oracle.com/javase/6/docs/api"/>
                                    <link packages="org.apache.tools.ant."
                                          href="http://evgeny-goldin.org/javadoc/ant/api"/>
                                    <link packages="org.junit.,junit.framework."
                                          href="http://kentbeck.github.com/junit/javadoc/latest"/>
                                    <link packages="groovy.,org.codehaus.groovy."
                                          href="http://groovy.codehaus.org/api/"/>
                                    <link packages="org.codehaus.gmaven."
                                          href="http://evgeny-goldin.org/javadoc/gmaven"/>
                                </groovydoc>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/groovydoc.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>groovydoc</id>
                        <phase>site</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

src/main/assembly/groovydoc.xml

代码语言:javascript
复制
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>groovydoc</id>
    <formats>
        <format>jar</format>
    </formats>

    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>${project.reporting.outputDirectory}/groovydoc</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

如果你运行

代码语言:javascript
复制
mvn site

在目标目录中会有一个groovydoc jar文件。

如果您希望在Default Lifecycle过程中创建<phase>site</phase>,可以将其更改为<phase>prepare-package</phase>。您必须更改生成的groovydoc所在的目录,才能使其正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13343411

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档