maven - 使用Gradle保存所有反射元数据

标签 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>

我不太了解自己实际需要做什么。

最佳答案

当前没有将Maven插件转换为Gradle插件的one2one转换器。通过查看第二个片段,您似乎可以为此简单地实现一个自定义任务,该任务调用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")
    }
}

关于maven - 使用Gradle保存所有反射元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33859303/

相关文章:

java - Jenkins :建立对其他工件/项目的依赖的工作

java - 重复的类com.google.api.Advice

java - 如何在你的库中使用 Spring-Data 以及如何在你的项目中使用这个库?

Java 11 - META-INF/服务中的注释 SPI 未得到确认

java - OSGI 传递依赖级别

eclipse - Eclipse下Maven增量编译

ubuntu - 安装 gradle 2.11 显示为 1.10