configuring existing eclipse java project to build using gradle

前端 未结 3 949
清酒与你
清酒与你 2020-12-08 14:18

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 E

3条回答
  •  执念已碎
    2020-12-08 14:47

    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!

提交回复
热议问题