# How to execute a task of type 'JavaExec' before compileJava

**URL:** https://discuss.gradle.org/t/how-to-execute-a-task-of-type-javaexec-before-compilejava/3741
**Category:** Old Forum Archive
**Created:** [October 22, 2013, 10:50pm UTC](https://discuss.gradle.org/t/how-to-execute-a-task-of-type-javaexec-before-compilejava/3741 "2013-10-22T22:50:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Amit\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Amit\_Agarwal](https://discuss.gradle.org/u/Amit_Agarwal)
#### Post date: [October 22, 2013, 10:50pm UTC](https://discuss.gradle.org/t/how-to-execute-a-task-of-type-javaexec-before-compilejava/3741/1 "2013-10-22T22:50:00Z")

</div>

I need to execute a java class which has a main method in it before compiling the code. This is what I have tried so far:

```gradle
task runSimple(type: JavaExec) {
    main = 'jjrom.ObjectGen'
    classpath = sourceSets.main.runtimeClasspath
    File prop1 = file(propFilePath)
       args '-sqlserver', '-force', prop1.path
    println "I'm done executing."
}
  compileJava {
    dependsOn runSimple
}

```

When I execute this script with the command “gradle compileJava” , I get this error message:

I’m done executing.

FAILURE: Build failed with an exception.

- What went wrong: Circular dependency between the following task: :classes — :compileJava

— :runSimple

— :classes (\*)

(\*) - details omitted (listed previously)

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [October 23, 2013, 10:14am UTC](https://discuss.gradle.org/t/how-to-execute-a-task-of-type-javaexec-before-compilejava/3741/2 "2013-10-23T10:14:00Z")

</div>

Please don’t double-post here and on Stack Overflow. I’ve already answered the question there.
