# Dependency from .jar file to .so from another project

**URL:** <https://discuss.gradle.org/t/dependency-from-jar-file-to-so-from-another-project/41570>\
**Category:** Help/Discuss\
**Created:** [November 30, 2021, 6:02am UTC](https://discuss.gradle.org/t/dependency-from-jar-file-to-so-from-another-project/41570 "2021-11-30T06:02:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnousterhout](https://avatars.discourse-cdn.com/v4/letter/j/839c29/32.png) [@johnousterhout](https://discuss.gradle.org/u/johnousterhout)\
**Post date:** [November 30, 2021, 6:02am UTC](https://discuss.gradle.org/t/dependency-from-jar-file-to-so-from-another-project/41570/1 "2021-11-30T06:02:46Z")

</div>

I’m trying to configure Gradle so that one project of a module contains the C++ code for a JNI extension, and another project creates a Java library whose .jar file contains both the Java classes from that project and also the .so file from the JNI project. I can get the .so file included in the .jar file, but I haven’t been able to figure out how to describe the dependency for the .so file properly.

Here is build.gradle for the jni project:

```gradle
plugins {
    id 'cpp-library'
}

library {
    targetMachines = [machines.linux.x86_64]

    tasks.withType(CppCompile).configureEach {
        compilerArgs.add '-Wall'
        compilerArgs.add '-Werror'
        compilerArgs.add '-fno-strict-aliasing'
        compilerArgs.add '-fPIC'
        compilerArgs.add '-I' + System.getenv("JAVA_HOME") + '/include'
        compilerArgs.add '-I' + System.getenv("JAVA_HOME") + '/include/linux'
    }
}

```

and here is the build.gradle file for the lib project:

```gradle
plugins {
    id 'java-library'
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'junit:junit:4.13.2'
    // implementation project(':jni')
}

jar {
    from('../jni/build/lib/main/debug') {
        include '*.so'
    }
}

```

With the `implementation` line commented out, the module builds and the .so file appears in the .jar file (but only after the second build), and Gradle complains about the lack of a dependency:

```gradle
- Gradle detected a problem with the following location: '/users/ouster/java/jni/build/lib/main/debug'. Reason: Task ':lib:jar' uses this output of task ':jni:linkDebug' without declaring an explicit or implicit dependency...

```

If I uncomment the `implementation` line, builds fail with this message:

```gradle
 > Could not resolve project :jni.
     Required by:
         project :lib
      > No matching variant of project :jni was found. The consumer was configured to find an API of a library compatible with Java 11, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally but:
          - Variant 'cppApiElements' capability grpc_homa:jni:unspecified:
...

```

I have tried several other ways of specifying the dependency, but none has worked for me. I suspect there must be an easy fix, but my newbie brain is stumped.

Any help would be much appreciated.

-John-
