2

I am making some kotlin JS wrappers for Firebase Javascript SDK. So I created the project with the external keyword and @file:JsModule annotation, something like that:

@file:JsModule("@firebase/messaging-types")
package my.package.firebase.messaging

import kotlin.js.Promise

external class FirebaseMessaging {
    fun getToken(): Promise<String?>
    ...
}

I can publish it to my local maven repository with this in my gradle:

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}
artifacts {
    archives sourcesJar
}
publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = project.group
            artifactId = 'firebase-wrappers'
            version = project.version
            from components.java
            artifact sourcesJar
        }
    }
}

How can I add NPM dependencies and make sure it will be available on the generated JAR file?

Allan Veloso
  • 5,823
  • 1
  • 38
  • 36

1 Answers1

1

Well actually you have a lot of options but the simplest one is to copy all you need in processResources task, something like:

processResources {
  from ('/some/js/resources') {
    include '**/*.js'
  }
}

This way any file will end up in the jar. However, keep in mind that as of now this won't affect running configurations in IntelliJ IDEA. That said, if you have running configuration even if it is based on gradle build this files still will be missed and this problem should be address differently.

The other useful technique is store this dependencies in a separate jar (possibly even in a different subproject) and have this jar as a runtime dependency.

shabunc
  • 23,119
  • 19
  • 77
  • 102