问题:将Eclipse Groovy项目转换为Gradle项目时出现的问题。

huangapple go评论89阅读模式
英文:

Issues with converting Eclipse Groovy project to Gradle project

问题

我有一个现有的Groovy项目,是在Eclipse IDE中创建的,项目结构如下:

  1. SposZohoMergeScript
  2. -- src
  3. -- com.xxx.sposZohoMergeScript
  4. -- com.xxx.sposZohoMergeScript.constants
  5. -- com.xxx.sposZohoMergeScript.factories
  6. -- com.xxx.sposZohoMergeScript.io
  7. -- com.xxx.sposZohoMergeScript.mergers
  8. -- com.xxx.sposZohoMergeScript.models
  9. -- com.xxx.sposZohoMergeScript.utils

我一直在手动下载、审核并将各个库和依赖的JAR文件添加到项目的构建路径中...更不用说没有内置的测试系统...我应该如何继续工作呢?!

是时候引入Gradle了!

我尝试使用Gradle插件,但它几乎立刻出现了问题...

我运行构建设置初始化步骤,它运行了很长时间...即使我去睡觉,几个小时后醒来,再次检查,它还在运行...

我关闭Eclipse IDE,打开BASH,在SposZohoMergeScript文件夹中运行 gradle init,它重新配置了我的项目。

我尝试将其设置为基本项目:

[![enter image description here][1]][1]

然后我创建了 build.gradle 文件:

  1. /*
  2. * This file was generated by the Gradle 'init' task.
  3. *
  4. * This is a general purpose Gradle build.
  5. * Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.2/samples
  6. */
  7. plugins {
  8. id 'java'
  9. id 'groovy'
  10. }
  11. repositories {
  12. mavenCentral()
  13. }
  14. dependencies {
  15. // https://mvnrepository.com/artifact/org.apache.poi/poi
  16. implementation 'org.apache.poi:poi:5.2.3'
  17. // https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
  18. implementation 'org.apache.poi:poi-ooxml:5.2.3'
  19. }

然后我运行 gradle build,运行成功。之后,我打开Eclipse,不仅看到我的文件夹结构混乱...

[![enter image description here][2]][2]

但当我尝试使用键盘快捷键创建构造函数时,出现错误,代码突出显示/IntelliSense无法理解我以前编写的代码:

[![enter image description here][4]][4]

我运行 gradle dependencies 用于项目,这是我得到的:

  1. > Task :dependencies
  2. ------------------------------------------------------------
  3. Root project 'SposZohoMergeScript'
  4. ------------------------------------------------------------
  5. annotationProcessor - Annotation processors and their dependencies for source set 'main'.
  6. No dependencies
  7. apiElements - API elements for main. (n)
  8. No dependencies
  9. archives - Configuration for archive artifacts. (n)
  10. No dependencies
  11. compileClasspath - Compile classpath for source set 'main'.
  12. +--- org.apache.poi:poi:5.2.3
  13. | +--- commons-codec:commons-codec:1.15
  14. | +--- org.apache.commons:commons-collections4:4.4
  15. | +--- org.apache.commons:commons-math3:3.6.1
  16. | +--- commons-io:commons-io:2.11.0
  17. | +--- com.zaxxer:SparseBitSet:1.2
  18. | \--- org.apache.logging.log4j:log4j-api:2.18.0
  19. \--- org.apache.poi:poi-ooxml:5.2.3
  20. +--- org.apache.poi:poi:5.2.3 (*)
  21. +--- org.apache.poi:poi-ooxml-lite:5.2.3
  22. | \--- org.apache.xmlbeans:xmlbeans:5.1.1
  23. | \--- org.apache.logging.log4j:log4j-api:2.18.0
  24. +--- org.apache.xmlbeans:xmlbeans:5.1.1 (*)
  25. +--- org.apache.commons:commons-compress:1.21
  26. +--- commons-io:commons-io:2.11.0
  27. +--- com.github.virtuald:curvesapi:1.07
  28. +--- org.apache.logging.log4j:log4j-api:2.18.0
  29. \--- org.apache.commons:commons-collections4:4.4
  30. compileOnly - Compile only dependencies for source set 'main'. (n)
  31. No dependencies
  32. default - Configuration for default artifacts. (n)
  33. No dependencies
  34. implementation - Implementation only dependencies for source set 'main'. (n)
  35. +--- org.apache.poi:poi:5.2.3 (n)
  36. \--- org.apache.poi:poi-ooxml:5.2.3 (n)
  37. runtimeClasspath - Runtime classpath of source set 'main'.
  38. +--- org.apache.poi:poi:5.2.3
  39. | +--- commons-codec:commons-codec:1.15
  40. | +--- org.apache.commons:commons-collections4:4.4
  41. | +--- org.apache.commons:commons-math3:3.6.1
  42. | +--- commons-io:commons-io:2.11.0
  43. | +--- com.zaxxer:SparseBitSet:1.2
  44. | \--- org.apache.logging.log4j:log4j-api:2.18.0
  45. \--- org.apache.poi:poi-ooxml:5.2.3
  46. +--- org.apache.poi:poi:5.2.3 (*)
  47. +--- org.apache.poi:poi-ooxml-lite:5.2.3
  48. | \--- org.apache.xmlbeans:xmlbeans:5.1.1
  49. | \--- org.apache.logging.log4j:log4j-api:2.18.0
  50. +--- org.apache.xmlbeans:xmlbeans:5.1.1 (*)
  51. +--- org.apache.commons:commons-compress:1.21
  52. +--- commons-io:commons-io:2.11.0
  53. +--- com.github.virtuald:curvesapi:1.07
  54. +--- org.apache.logging.log4j:log4j-api:2.18.0
  55. \--- org.apache.commons:commons-collections4:4.4
  56. runtimeElements - Elements of runtime for main. (n)
  57. No dependencies
  58. runtimeOnly - Runtime only dependencies for source set 'main'. (n)
  59. No dependencies
  60. testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
  61. No dependencies
  62. testCompileClasspath
  63. <details>
  64. <summary>英文:</summary>
  65. I have an existing Groovy project, created with the Eclipse IDE, defined to be:

SposZohoMergeScript
-- src
-- com.xxx.sposZohoMergeScript
-- com.xxx.sposZohoMergeScript.constants
-- com.xxx.sposZohoMergeScript.factories
-- com.xxx.sposZohoMergeScript.io
-- com.xxx.sposZohoMergeScript.mergers
-- com.xxx.sposZohoMergeScript.models
-- com.xxx.sposZohoMergeScript.utils

  1. I have been *manually* downloading, vetting, and bringing into the project build path the individual JAR files per each library and dependency... Not to mention there&#39;s no built-in system for testing... How am I supposed to keep working like this?!
  2. It&#39;s time to bring in Gradle!
  3. I try the Gradle plugin, and it goes sideways pretty much immediately...
  4. I run the build setup init step, and it runs forever...even if I go to sleep, wake up a few hours later, and check back on it, it&#39;s still there...
  5. I close the Eclipse IDE, open up the BASH, on the SposZohoMergeScript folder, run `gradle init` myself, and it re-fucktors my project.
  6. I try to set it up as basic project:
  7. [![enter image description here][1]][1]
  8. I then create the `build.gradle`:

/*

  • This file was generated by the Gradle 'init' task.
    *
  • This is a general purpose Gradle build.
  • Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.2/samples
    */
    plugins {
    id 'java'
    id 'groovy'
    }

repositories {
mavenCentral()
}

dependencies {
// https://mvnrepository.com/artifact/org.apache.poi/poi
implementation 'org.apache.poi:poi:5.2.3'
// https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
implementation 'org.apache.poi:poi-ooxml:5.2.3'

}

  1. I then do a `gradle build`, which runs successfully. After that, I open up the Eclipse, and not only do I see my folder structure all messed up...
  2. [![enter image description here][2]][2]
  3. but when I go to, for example, use the keyboard shortcuts to create a constructor, it gives me error, and the highlighter/IntelliSense can&#39;t make sense of previously-working code I have written:
  4. [![enter image description here][4]][4]
  5. I run `gradle dependencies` for the project, and this is what I get:

> Task :dependencies


Root project 'SposZohoMergeScript'

annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies

apiElements - API elements for main. (n)
No dependencies

archives - Configuration for archive artifacts. (n)
No dependencies

compileClasspath - Compile classpath for source set 'main'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| --- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 ()
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| --- org.apache.xmlbeans:xmlbeans:5.1.1
| --- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (
)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.commons:commons-collections4:4.4

compileOnly - Compile only dependencies for source set 'main'. (n)
No dependencies

default - Configuration for default artifacts. (n)
No dependencies

implementation - Implementation only dependencies for source set 'main'. (n)
+--- org.apache.poi:poi:5.2.3 (n)
--- org.apache.poi:poi-ooxml:5.2.3 (n)

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| --- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 ()
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| --- org.apache.xmlbeans:xmlbeans:5.1.1
| --- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (
)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.commons:commons-collections4:4.4

runtimeElements - Elements of runtime for main. (n)
No dependencies

runtimeOnly - Runtime only dependencies for source set 'main'. (n)
No dependencies

testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies

testCompileClasspath - Compile classpath for source set 'test'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| --- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 ()
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| --- org.apache.xmlbeans:xmlbeans:5.1.1
| --- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (
)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.commons:commons-collections4:4.4

testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies

testImplementation - Implementation only dependencies for source set 'test'. (n)
No dependencies

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| --- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 ()
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| --- org.apache.xmlbeans:xmlbeans:5.1.1
| --- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (
)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
--- org.apache.commons:commons-collections4:4.4

testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies

(*) - dependencies omitted (listed previously)

(n) - Not resolved (configuration is not meant to be resolved)

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed

  1. I am using Eclipse IDE Version: 2022-09 (4.25.0), Build id: 20220908-1902 , and Gradle 7.2, on Windows 10 64-bit computer .
  2. What can I do to get Gradle working with the Eclipse?
  3. [1]: https://i.stack.imgur.com/pvjOO.png
  4. [2]: https://i.stack.imgur.com/OwjfX.png
  5. [4]: https://i.stack.imgur.com/BvAlo.png
  6. </details>
  7. # 答案1
  8. **得分**: 1
  9. 根据您的屏幕截图来看,Gradle的目录结构不正确。
  10. 按照约定,JavaGroovy插件配置其源集为`src/main/java``src/main/groovy`
  11. * Java插件:https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_project_layout
  12. * Groovy插件:https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_project_layout
  13. 您的截图显示只有`src/`,然后是您的代码/包。将您的代码移动到`src/main/groovy/`(对于Groovy代码)和`src/main/java`(对于Java代码)下。
  14. 要在Eclipse中更正项目结构,请执行以下操作:
  15. 1. **右键单击**项目,选择***New > Folder***,创建文件夹**`src/main/java`**。
  16. 2. **将文件夹** **`src/com`** 移动到**`src/main/java`**。
  17. 3. **右键单击 `src/main/java`**,选择***Build Path > Use As Source Folder***。
  18. <details>
  19. <summary>英文:</summary>
  20. Based on your screenshot alone, the directory structure is not correct for Gradle.
  21. By convention, the Java and Groovy plugin configure their source sets to be `src/main/java` and `src/main/groovy`:
  22. * https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_project_layout
  23. * https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_project_layout
  24. Your screenshot shows that you only have `src/` followed by your code/package. Move your code to be under `src/main/groovy/` for Groovy code and `src/main/java` for Java code.
  25. To correct your project structure in Eclipse do the following:
  26. 1. **Right-click** the **project** and choose ***New &gt; Folder*** and create the folder **`src/main/java`**
  27. 2. **Move** the folder **`src/com` into `src/main/java`**
  28. 3. **Right-click `src/main/java`** and choose ***Build Path &gt; Use As Source Folder***
  29. </details>

huangapple
  • 本文由 发表于 2023年2月19日 05:25:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75496491.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定