0

I am migrating my project from Maven to Gradle and i have a Java Class that i need to have compiled before the rest of the project. This class creates a file that will be used by the project. Does anyone have an idea how to accomplish this task? Thanks

Edit:

The following is the Maven solution:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>11</release>
    </configuration>
    <executions>
        <execution>
            <id>default-compile</id>
            <configuration>
                <compilerArgument>-proc:none</compilerArgument>
                <includes>
                    <include>PATH/TO/CLASS/AnnotationProcessor.java</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>compile-project</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The AnnotationProcessor scrapes and stores all annotation data that the project declares. This class is supposed to be compiled before the rest of the project. At least that is what the comment section says.

Rob Evans
  • 2,822
  • 1
  • 9
  • 15
widdow
  • 5
  • 2
  • I do not understand what you want to achieve. If you are migrating from Maven to Gradle, you already solved this problem in Maven. Could you show how you solved it in Maven? – Lukas Körfer Oct 02 '20 at 11:43
  • I edited my post and added the Maven solution – widdow Oct 02 '20 at 13:21
  • 2
    I think maybe you want the annotation processor to be in its own project? – Michal Oct 02 '20 at 13:21
  • That might be one option I read about. Are there other ways, maybe a task-based solution? I know that Gradle creates a DAG with what to do in which order. Does this DAG accepts something like a "dependsOn"? Is it even possible to "split-compile" a project? Like, compile this part first, and when it's done build the rest – widdow Oct 02 '20 at 13:33

1 Answers1

0

Seems like you have some class that needs to exist before the rest of the project can be built. One way to resolve this would be to extract the dependency to a separate module so you have a multiproject build... This post may help you achieve what you want.

Build order of Maven multimodule project?

You can also introduce custom tasks in Gradle that will enable you to have "dependsOn(someTask)"

See https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:task_dependencies for more/examples

Rob Evans
  • 2,822
  • 1
  • 9
  • 15