1

There's a snippet that shows how to save all Reflections metadata at build time so bootstrapping time is reduced here. The problem is it uses Maven and I want to do this with Gradle. Could anyone please help me to convert this Maven configuration to Gradle configuration?

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

Also on github there is another snippet:

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

I don't really understand what I actually need to do.

nikoliazekter
  • 757
  • 2
  • 6
  • 23

1 Answers1

0

There is currently no one2one converter for converting maven plugins into gradle plugins. From looking at your 2nd snippet It seems that you can simply implement a custom task for this that invokes the Reflections.save method. A possible solution could look close to this snippet:

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")
    }
}
Rene Groeschke
  • 27,999
  • 10
  • 69
  • 78