【问题标题】:Using Gradle to save all Reflections metadata使用 Gradle 保存所有 Reflections 元数据
【发布时间】:2015-11-22 19:36:46
【问题描述】:

有一个 sn-p 显示如何在构建时保存所有反射元数据,从而减少引导时间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 上还有另一个 sn-p:

<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 reflections


    【解决方案1】:

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

    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")
        }
    }
    

    【讨论】:

    • “在任务中找不到属性 'org'”。我试图从 IntelliJ IDEA 运行任务。
    • 你也试过命令行吗?看来这门课不是正确的。
    猜你喜欢
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 2023-03-02
    • 1970-01-01
    • 2011-02-15
    • 2021-02-25
    • 2016-05-02
    相关资源
    最近更新 更多