# Build java project with gradle

**URL:** <https://discuss.gradle.org/t/build-java-project-with-gradle/20744>\
**Category:** Help/Discuss\
**Created:** [December 7, 2016, 5:47pm UTC](https://discuss.gradle.org/t/build-java-project-with-gradle/20744 "2016-12-07T17:47:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aymen](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@Aymen](https://discuss.gradle.org/u/Aymen)\
**Post date:** [December 7, 2016, 5:47pm UTC](https://discuss.gradle.org/t/build-java-project-with-gradle/20744/1 "2016-12-07T17:47:30Z")

</div>

hey all,

I want to compile a java project with gradle, i tried with the script but the problem is that i have jars that are defined in the file .classpath and in the lib repertory but it’s not reading the jars.

```
apply plugin: 'java'
apply plugin:'application'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
   main {
      java {
         srcDir 'src'
      }
   }
}
repositories {
    mavenCentral()
}
dependencies {
   compile 'org.slf4j:slf4j-api:1.7.12'
   testCompile 'junit:junit:4.12'
}

```

Then I executed the script with this command : gradle build

The project structure:

 ![](https://global.discourse-cdn.com/gradle/original/2X/2/23861661e5ceb3a11df3170e24f51e4dbe02bc28.png)

file .classpath :

```
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="src" path="src"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
	<classpathentry kind="lib" path="/app/ATG/ATG11.2/DCS/lib/resources.jar"/>
	<classpathentry kind="lib" path="/app/ATG/ATG11.2/DCS/lib/classes.jar"/>
        ........
	<classpathentry kind="output" path="classes"/>
</classpath>

```

Regards.

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [December 7, 2016, 6:22pm UTC](https://discuss.gradle.org/t/build-java-project-with-gradle/20744/2 "2016-12-07T18:22:42Z")

</div>

Gradle does not consider the eclipse ‘…classparh’ file. to get the dependencies added to your gradle build you can either reference the files in the lib folder explicitly by

’’’  
dependencies {  
compile filetree(‘lib’)  
}  
‘‘‘

Alternatively you can declare a file based repository pointing to “lib” and reference each dependency in the dependencies block as you tried it in your sample. Learn more about file repositories at the according chapter in the gradle userguide at [https://docs.gradle.org/current/userguide/dependency\_management.html#sec:flat\_dir\_resolver](https://docs.gradle.org/current/userguide/dependency_management.html#sec:flat_dir_resolver)

Once you have solved this you can apply the eclipse plugin and generate the eclipse ’.project’ and ’.classpath’ files from gradle

cheers,  
rene
