gpt4 book ai didi

java - 配置现有的 eclipse java 项目以使用 gradle 构建

转载 作者:IT老高 更新时间:2023-10-28 21:12:12 25 4
gpt4 key购买 nike

我在 Eclipse 中有一个现有的 Java 项目。我想使用 gradle 实现构建。我尝试使用给定的 gradle eclipse 插件 here但在 Eclipse 中遇到了许多错误。

我使用的是 gradle 1.3,我尝试从命令提示符运行 gradle,但出现编译错误。

所以我的问题是,有没有人知道一些很好的资源,它提供了如何将 Eclipse 中的现有 java 项目转换为使用 gradle 编译的方法。我对其他项目也有一些依赖。我提供的教程链接并没有真正的帮助。

更新:如果我的项目不依赖其他项目,我可以让 gradle 工作。但是,如果它确实引用了其他项目,我不知道如何引用另一个项目?我已将引用的项目目录添加到存储库,但我仍然收到“类不存在”错误。我的 gradle 文件如下:

apply plugin: 'java'
apply plugin: 'eclipse'

version='1.0-SNAPSHOT'

def repositoryPath = 'C:/Users/AMoody/workspace/temp/temp-protocols/'

repositories{
mavenCentral()
flatDir {
dirs repositoryPath
}
}

dependencies{

compile 'org.slf4j:slf4j-api:1.+'
compile 'junit:junit:4.+'
testCompile 'junit:junit:4.+'

}

最佳答案

好的,如果你有一个简单的java项目,它的目录/文件结构如下

enter image description here

步骤一:在项目根目录下创建文件名build.gradle,如下

enter image description here

Step-2:build.gradle

中添加以下gradle脚本
apply plugin: 'java'
apply plugin: 'eclipse'
archivesBaseName = 'someJar'
version = '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

jar {
manifest {
attributes 'Main-Class': 'com.test.Run'
}
}

dependencies {
compile 'log4j:log4j:1.2.16'
}

第3步:关闭或从eclipse中删除该项目并再次导入,同时选择Gradle项目如下

enter image description here

enter image description here

现在您的项目层次结构将如下所示。 (还要注意它在导入项目时添加的 Gradle 依赖项)

enter image description here

步骤 4: 在项目中创建源文件夹 src/main/java 并将所有包移动到该源文件夹中。

enter image description here

第 5 步最后但并非最不重要: 干杯 :)

所以现在您的 Simple Java 项目已转换为 Gradle 项目!

关于java - 配置现有的 eclipse java 项目以使用 gradle 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14615872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com