【问题标题】:Gradle - Is there a possibility to compile a single Java class before the rest of the project?Gradle - 是否有可能在项目的其余部分之前编译单个 Java 类?
【发布时间】:2021-01-17 23:04:10
【问题描述】:

我正在将我的项目从 Maven 迁移到 Gradle,并且我有一个 Java 类,我需要在项目的其余部分之前编译它。此类创建一个将由项目使用的文件。 有谁知道如何完成这项任务?谢谢

编辑:

以下是Maven解决方案:

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

AnnotationProcessor 抓取并存储项目声明的所有注释数据。这个类应该在项目的其余部分之前编译。至少评论区是这么说的。

【问题讨论】:

  • 我不明白你想要达到什么目的。如果您正在从 Maven 迁移到 Gradle,那么您已经在 Maven 中解决了这个问题。你能展示一下你是如何在 Maven 中解决它的吗?
  • 我编辑了我的帖子并添加了 Maven 解决方案
  • 我想也许你希望注释处理器在它自己的项目中?
  • 这可能是我读到的一个选项。还有其他方法吗,也许是基于任务的解决方案?我知道 Gradle 创建了一个 DAG,其中包含按什么顺序执行的操作。此 DAG 是否接受类似“dependsOn”的内容?甚至可以“拆分编译”一个项目吗?就像,先编译这部分,完成后构建其余部分

标签: java gradle build.gradle gradle-plugin annotation-processing


【解决方案1】:

在构建项目的其余部分之前,您似乎需要存在一些类。解决此问题的一种方法是将依赖项提取到单独的模块中,以便您进行多项目构建...这篇文章可能会帮助您实现所需的目标。

Build order of Maven multimodule project?

您还可以在 Gradle 中引入自定义任务,使您能够拥有“dependsOn(someTask)”

查看https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:task_dependencies了解更多/示例

【讨论】:

  • 谢谢。我会看看这个
猜你喜欢
  • 2018-06-04
  • 1970-01-01
  • 1970-01-01
  • 2015-05-14
  • 2013-04-02
  • 2020-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多