简体   繁体   中英

configuring existing eclipse java project to build using gradle

I have an existing Java project in Eclipse. I want to implement builds using gradle. I tried using the gradle eclipse plugin as given here but ran into numerous errors in Eclipse.

I am using gradle 1.3, and I tried running gradle from command prompt, but I get compilation errors.

So my question is, does anyone know of some good resource which offers a how-to for converting an existing java project in Eclipse to compile using gradle. I also have some dependencies on other projects. The link to the tutorial I have given is not really helpful.

UPDATE: I can get gradle to work if my project doesn't have dependencies on other projects. However, if it does refer to some other project, I can't figure out how to reference another project? I have added the referenced project dir to repositories but I still get "class does not exist" errors. My gradle file is as below:

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.+'

}

Okay, So if you have simple java project which has dir/file structure as below

在此输入图像描述

Step-1: create file name build.gradle in project root directory as below

在此输入图像描述

Step-2: add following gradle script in build.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'
} 

Step-3: close or delete from eclipse this project and import it again while selecting Gradle project as below

在此输入图像描述

在此输入图像描述

Now your project hierarchy will look like this. (Also note its added Gradle Dependencies while importing project)

在此输入图像描述

Step-4: Create source foler src/main/java in project and move your all packages in that source folder.

在此输入图像描述

Step-5 last but not the least: Cheers :)

So now your Simple Java project has converted into Gradle project!

The first couple of chapters of the Gradle User Guide , along with the many (Java) samples in the full Gradle distribution , should get you started. It doesn't matter all that much whether your current build is Eclipse or something else; to be successful with Gradle, you'll first have to master its fundamentals.

Once you have the Gradle command line build working, you can give the IDE integration another shot. Depending on your preferences, you can either generate IDE files with Gradle's Eclipse plugin (again see the samples in the full Gradle distribution), or use the Eclipse Gradle Integration for a more integrated IDE experience.

Check out the Gradle homepage for additional resources. When faced with a concrete question about Gradle's build language, consult the Gradle DSL Reference . A full-text search over the single-page Gradle User Guide can also be quite effective. Last but not least, make sure to visit the Gradle Forums .

尝试使用Gradle的Eclipse集成: http//marketplace.eclipse.org/content/buildship-gradle-integration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM