将 Eclipse java 项目(带有 java 源文件夹)转换为 gradle 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16665602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:32:54  来源:igfitidea点击:

Convert Eclipse java project (with java source folder) to gradle project

javaeclipsegradle

提问by naike

I want to migrate all my java projects(223 projects) to gradle project. I'm using the Gradle Eclipse plugin, developed by the SpringSource STS team.

我想将我所有的java 项目(223 个项目)迁移到gradle 项目。我正在使用由 SpringSource STS 团队开发的 Gradle Eclipse 插件。

Currently, all my java projets is strutured like that:

目前,我所有的 Java 项目都是这样构建的:

MyProjet/
+- src/log
    +- some.package.log
    +- some.package.log.A
+- src/tools/core
    +- some.package
    +- some.package.tools.B
    +- some.package.tools.C
+- src/tools/graph
    +- some.package.graph
+- src/tests
    +- some.package.test.D
+- src/someModule

+- otherDirectories

src/log, src/tools/core, src/tools/graph, src/tests and src/someModule are java source folders.

src/log、src/tools/core、src/tools/graph、src/tests 和 src/someModule 是java 源文件夹

After converting the project to gradle (via Configure -> "Convert to Gradle Project..."), all java source folders become packages.

将项目转换为 gradle(通过配置 ->“转换为 Gradle 项目...”)后,所有 java 源文件夹都成为包。

Also, the matter is that all declared packages in java classes must be modified. For example, Eclipse tell me that: The declared package "some.package.test.tools.A" does not match the expected package "tests.some.package.test.tools.A"

此外,问题是必须修改 java 类中所有声明的包。例如,Eclipse 告诉我:声明的包“some.package.test.tools.A”与预期的包“tests.some.package.test.tools.A”不匹配

Eclipse give me the possibility to change the package declaration of a class. But I must do that for all classes (sometimes more than 100 classes for one project).

Eclipse 使我可以更改类的包声明。但是我必须对所有课程都这样做(有时一个项目有 100 多个课程)。

I want to know if there is a way to convert a java project (with java source folder) to a gradle project, without impacting all packages (I would like to avoid the operation that consist in modifiyng all classes)

我想知道是否有一种方法可以在不影响所有包的情况下将 java 项目(带有 java 源文件夹)转换为 gradle 项目(我想避免包含修改所有类的操作)

Thank you in advance for help or any advices.

预先感谢您的帮助或任何建议。

Naike.

奈克。

采纳答案by Peter Niederwieser

You'll have to write Gradle build script(s) and, among other things, declare your source directory structure there. (You don't have to change the source directory structure or any package statements.) "Convert to Gradle Project" won't do this for you. It's merely a way to activate Gradle support for the project, which will make Eclipse use information contained in the Gradle build scripts, allow you to execute a Gradle build from the IDE, etc.

您必须编写 Gradle 构建脚本,并在其中声明源目录结构。(您不必更改源目录结构或任何包语句。)“转换为 Gradle 项目”不会为您执行此操作。这只是为项目激活 Gradle 支持的一种方式,这将使 Eclipse 使用 Gradle 构建脚本中包含的信息,允许您从 IDE 执行 Gradle 构建等。

回答by Michal Borek

I think the best way you can do is to change "source folder" under, by doing following steps:

我认为您可以做的最好的方法是通过执行以下步骤更改“源文件夹”:

  1. Open Project preferences
  2. Open Java Build Path
  3. Under "Source" tab there is "Source folders on build path". You can customize it so that "src" is a source folder and not the "/" one (because I guess that has changed after project migration).
  1. 打开项目首选项
  2. 打开 Java 构建路径
  3. 在“源”选项卡下有“构建路径上的源文件夹”。您可以自定义它,以便“src”是源文件夹而不是“/”文件夹(因为我猜这在项目迁移后发生了变化)。

I hope that helps!

我希望这有帮助!