1

有一个片段显示了如何在构建时保存所有反射元数据,因此这里的引导时间减少。问题是它使用 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>

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

4

1 回答 1

0

目前没有用于将 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")
    }
}
于 2015-11-23T07:04:07.743 回答