Including the compiled root project in a subproject's JAR

I am writing a wrapper API in Java for two different software platforms that essentially do the same thing but with slightly different method names. My root project contains all abstract (platform-independent) APIs that are shared between both implementations, and each platform-specific implementation resides in its own subproject. Both of these subprojects require the compiled code from the root project to be present in their respective compiled JAR archive.

My root project’s build.gradle looks something like this:

plugins {
    id 'java'
}

group = 'com.domain.project'
version = '0.1.0-ALPHA'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    // ...
}

dependencies {
    // ...
}

subprojects {
    dependencies {
        rootProject
    }
}

And this is the build.gradle for one of my subprojects:

plugins {
    'java'
}

group = 'com.domain.project'
version = '0.1.0-ALPHA'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    // ...
}

dependencies {
    implementation rootProject
    // ...
}

However, when executing the subproject’s jar task, I get two JARs: one inside the subproject’s build directory containing only the platform-specific classes and one inside the root one’s with the abstraction layer. How can I make Gradle include the root project’s abstract classes inside the subproject’s JAR? And is this a sane structure for this type of project at all? I am fairly new to Gradle, so please forgive me if I got something totally wrong. Thanks in advance!