使用Gradle保存所有Reflections元数据

时间:2015-11-22 19:36:47

标签: maven gradle google-reflections

有一个片段显示如何在构建时保存所有Reflections元数据,因此引导时间减少here。 问题是它使用Maven,我想用Gradle做这个。有人可以帮我把这个Maven配置转换成Gradle配置吗?

<build>
    <plugins>
        <plugin>
            <groupId>org.reflections</groupId>
            <artifactId>reflections-maven</artifactId>
            <version>the latest version...</version>
            <executions>
                <execution>
                    <goals>
                        <goal>reflections</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

同样在github上还有另一个代码段:

<plugin>
    <groupId>org.codehaus.gmavenplus</groupId>
    <artifactId>gmavenplus-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <scripts>
                    <script><![CDATA[
                        new org.reflections.Reflections("f.q.n")
                            .save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
                    ]]></script>
                </scripts>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <!-- use latest version of Reflections -->
            <version>0.9.10</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <!-- any version of Groovy \>= 1.5.0 should work here -->
            <version>2.4.3</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>

我真的不明白我实际需要做什么。

1 个答案:

答案 0 :(得分:0)

目前还没有one2one转换器将maven插件转换为gradle插件。从查看您的第二个片段看起来您可以简单地为此调用Reflections.save方法实现自定义任务。一个可能的解决方案可能看起来接近这个片段:

buildscript {
    dependencies {
        // for resolving reflections dependencies
        mavenCentral()
    }

    dependencies {
        // add reflections dependency to your build classpath
        classpath "org.reflections:reflections:0.9.10"
    }
}


task runReflections {
    doLast {
        org.reflections.Reflections("f.q.n").save("${sourceSet.main.output.classesDir}/META-INF/reflections/${your-xml-file-name}.xml")
    }
}