# Native - Can't specify 'dependsOn' tasks for CPP compilation tasks

**URL:** https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700
**Category:** Help/Discuss
**Created:** [April 7, 2015, 6:20pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700 "2015-04-07T18:20:33Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Jesus\_Zazueta](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jesus_zazueta/32/197_2.png) [@Jesus\_Zazueta](https://discuss.gradle.org/u/Jesus_Zazueta)
#### Post date: [April 7, 2015, 6:20pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/1 "2015-04-07T18:20:33Z")

</div>

Hi. Like the title says.

I’m using Gradle 2.3 to generate and compile SWIG wrappers for an application. When typing `gradle tasks` on my project, I see some tasks for each library configured in the project, like so:

```
compileMyExampleLibSharedLibraryMyExampleLibCpp
linkMyExampleLibSharedLibrary

```

Now, if I have a dependent task `swig`, that generates Java wrappers for the C++ code, I can’t use this:

```
compileMyExampleLibSharedLibraryMyExampleLibCpp.dependsOn swig

```

Error:

```
* What went wrong:
A problem occurred evaluating project ':jni-native'.
> Could not find property 'compileMyExampleLibSharedLibraryMyExampleLibCpp' on project ':jni-native'.

```

It seems as if the task above gets defined at runtime.

Also, I can’t apply the `cpp` and `java` plugins at the same time to compile mixed C++/Java sources.

Any help/guidance is appreciated. Thanks!

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [April 7, 2015, 6:24pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/2 "2015-04-07T18:24:18Z")

</div>

This configuration needs to go in a `model { }` block. Please see [the Gradle 2.2 release notes](http://gradle.org/docs/2.2/release-notes#publishing-plugins-and-native-language-support-plugins-changes) for details.

```
model {
    tasks.compileMyExampleLibSharedLibraryMyExampleLibCpp {
        dependsOn swig
    }
}
```

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [April 7, 2015, 6:30pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/3 "2015-04-07T18:30:04Z")

</div>

> [@Jesus\_Zazueta](#):
>
> Also, I can’t apply the cpp and java plugins at the same time to compile mixed C++/Java sources.

This should be possible. Are you receiving an error?

---

<div class="post-metadata">

### Author: ![Jesus\_Zazueta](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jesus_zazueta/32/197_2.png) [@Jesus\_Zazueta](https://discuss.gradle.org/u/Jesus_Zazueta)
#### Post date: [April 8, 2015, 6:30am UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/4 "2015-04-08T06:30:19Z")

</div>

Hi. Yeah, as soon as I say `apply plugin: 'java'`, I get:

```
FAILURE: Build failed with an exception.

* Where:
Build file '/Users/jzazueta/code/octave-interop/octjni-native/build.gradle' line: 25

* What went wrong:
A problem occurred evaluating project ':octjni-native'.
> Could not find property 'cppCompiler' on classes 'main'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

```

My best guess is that some object instance might be getting replaced by whatever the ‘java’ plugin does internally. Thanks for the help!

---

<div class="post-metadata">

### Author: ![Jesus\_Zazueta](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jesus_zazueta/32/197_2.png) [@Jesus\_Zazueta](https://discuss.gradle.org/u/Jesus_Zazueta)
#### Post date: [April 8, 2015, 6:35am UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/5 "2015-04-08T06:35:30Z")

</div>

Your suggestion for the first problem above worked. Yay!

BTW that note should probably be referenced in the native binaries documentation section. Thanks again!

---

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [April 8, 2015, 4:14pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/6 "2015-04-08T16:14:40Z")

</div>

Can you share your build script so we can get a better idea of what’s going on?

---

<div class="post-metadata">

### Author: ![Jesus\_Zazueta](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jesus_zazueta/32/197_2.png) [@Jesus\_Zazueta](https://discuss.gradle.org/u/Jesus_Zazueta)
#### Post date: [April 8, 2015, 5:43pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/7 "2015-04-08T17:43:58Z")

</div>

Sure man. I’ll upload a slimmed down version of it to my github repo later today.

Thanks for the help!

---

<div class="post-metadata">

### Author: ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)
#### Post date: [April 8, 2015, 10:27pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/8 "2015-04-08T22:27:52Z")

</div>

If I had to guess, I bet you’re doing something like this:

```gradle
binaries.all {
   cppCompiler.define 'SOMETHING'
}

```

Under the covers, the Java plug-in puts things in the `binaries` container too, so you’re trying to configure the cppCompiler on a collection of classes. In a mixed project, you’re better off being a little more explicit and selecting a particular type of binary:

```gradle
binaries.withType(NativeBinary) {
   cppCompiler.define 'SOMETHING'
}

```

HTH

---

<div class="post-metadata">

### Author: ![Jesus\_Zazueta](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jesus_zazueta/32/197_2.png) [@Jesus\_Zazueta](https://discuss.gradle.org/u/Jesus_Zazueta)
#### Post date: [April 8, 2015, 11:24pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/9 "2015-04-08T23:24:04Z")

</div>

Yup, that did the trick man. Restricting the `binaries` predicate made the `java` plugin stop complaining. Now I’ll refactor my code to see if I can export a JNI jar inside a single project in one fell swoop.

Maybe this could make a nice contribution to the Gradle user manual right? Perhaps a section for those looking to build SWIG wrappers? I’ll let you guys know if I stumble upon any other roadblocks.

Cheers!

---

<div class="post-metadata">

### Author: ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)
#### Post date: [April 9, 2015, 1:12am UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/10 "2015-04-09T01:12:24Z")

</div>

We love [contributions](http://discuss.gradle.org/t/developer-guidelines/108).

I think a single project mixed Java/C++ sample would be pretty cool. It wouldn’t have to use something elaborate (i.e., use SWIG) to just demonstrate that it’s possible to do that and maybe outline some gotchas. If you’d like to discuss it more, please hit the [gradle-dev list](https://groups.google.com/forum/#!forum/gradle-dev).

---

<div class="post-metadata">

### Author: ![Jesus\_Zazueta](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jesus_zazueta/32/197_2.png) [@Jesus\_Zazueta](https://discuss.gradle.org/u/Jesus_Zazueta)
#### Post date: [April 10, 2015, 2:18pm UTC](https://discuss.gradle.org/t/native-cant-specify-dependson-tasks-for-cpp-compilation-tasks/8700/11 "2015-04-10T14:18:19Z")

</div>

Will do. Thanks again yo!
