Kotlin/Js add npm dependency from custom registry - kotlin

I'm developing an application with Kotlin/JS and Gradle. I can easily add npm dependencies from the default npm registry with the implementation npm("query-string", "7.0.0") command.
However, I cannot add an npm dependency from a different npm registry like Github Packages.
I want to add this npm dependency to my project. Without gradle I could just install the dependency by just using the command line and npm install #gitliveapp/firebase-firestore but this doesn't work with the gradle npm command. I also tried implementation npm("#gitliveapp/firebase-firestore", "0.5.4") but this produces the following error: Couldn't find package "#gitliveapp/firebase-firestore#0.5.4" required by "project" on the "npm" registry..
How can I add npm dependencies with gradle from different registries other than the npm public registry.
build.gradle
plugins {
id 'org.jetbrains.kotlin.js' version '1.5.10'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.0'
}
repositories {
mavenCentral()
maven { url 'https://maven.pkg.jetbrains.space/public/p/kotlin/p/kotlin/kotlin-js-wrappers' }
}
dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test-js'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react', version: '17.0.2-pre.212-kotlin-1.5.10'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react-dom', version: '17.0.2-pre.212-kotlin-1.5.10'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-styled', version: '5.3.0-pre.212-kotlin-1.5.10'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react-router-dom', version: '5.2.0-pre.212-kotlin-1.5.10'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-css', version: '1.0.0-pre.212-kotlin-1.5.10'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-redux', version: '4.0.5-pre.212-kotlin-1.5.10'
implementation group: 'org.jetbrains.kotlin-wrappers', name: 'kotlin-react-redux', version: '7.2.3-pre.212-kotlin-1.5.10'
implementation 'dev.gitlive:firebase-firestore:1.3.1'
implementation 'dev.gitlive:firebase-auth:1.3.1'
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation 'org.kodein.di:kodein-di-js:7.6.0'
implementation npm("query-string", "7.0.0")
implementation npm("firebase", "8.6.8")
implementation npm("#gitliveapp/firebase-firestore", "0.5.4")
}
kotlin {
js(LEGACY) {
binaries.executable()
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile).all {
kotlinOptions {
freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
}
}

Unfortunately, you can't do it via gradle now, see an issue.
But you can create file .npmrc (or .yarnrc) in the project root and configure here (https://docs.npmjs.com/configuring-npm/npmrc.html)
Additionally see the documentation:
For example, to use a custom registry for npm packages, add the following line to a file called .yarnrc in the project root: registry "http://my.registry/api/npm/"

Related

Gradle Task has not declared any outputs despite executing actions

i use gradle-wrapper and have Gradle 6.8 installed.
Succesfull Runs:
bash gradlew check
bash gradlew test
Failed Runs:
`
Task :findMainClass FAILED
Caching disabled for task ':findMainClass' because:
Build cache is disabled
Task ':findMainClass' is not up-to-date because:
Task has not declared any outputs despite executing actions.
:findMainClass (Thread[Execution worker for ':',5,main]) completed. Took 0.001 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':findMainClass'.
'java.io.File org.gradle.api.tasks.SourceSetOutput.getClassesDir()'
`
This is my build.gradle:
`
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
}
}
ext {
bootVersion = "1.5.2.RELEASE"
}
//apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
//mavenLocal()
//maven { url "http://repo.springsource.org/snapshot" }
//maven { url "http://repo.springsource.org/milestone" }
maven { url "https://repo.spring.io/libs-snapshot" }
}
dependencies {
implementation group: 'org.springframework.cloud', name: 'spring-cloud-core', version: '1.2.9.RELEASE'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-spring-service-connector', version: '1.2.9.RELEASE'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector', version: '1.2.9.RELEASE'
implementation "org.springframework.boot:spring-boot-starter-actuator:${bootVersion}"
implementation "org.springframework.boot:spring-boot-starter-tomcat:${bootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${bootVersion}"
implementation "org.springframework.boot:spring-boot-starter-data-jpa:${bootVersion}"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf:${bootVersion}"
implementation 'com.amazonaws:aws-java-sdk:1.11.113'
runtimeOnly "org.yaml:snakeyaml:1.18"
runtimeOnly "mysql:mysql-connector-java:6.0.6"
implementation group: 'net.minidev', name: 'json-smart', version: '2.3'
}
task wrapper1(type: Wrapper) {
gradleVersion = '6.0.1'
}
`
and this is my gradle-wrapper.properties:
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=file:///tmp/my-project/gradle-6.8-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
Can you help me to solve this issue?
I was trying to deploy an cloudfoundry test applciation: https://github.com/cloudfoundry-samples/cf-s3-demo

Gradle selenium(any) dependencies are not downloading

After creating new java gradle project added following dependencies in build file.
enter image description here
dependencies {
// Use JUnit Jupiter for testing.
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '4.3.0'
// https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
implementation group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.3.0'
// https://mvnrepository.com/artifact/org.testng/testng
testImplementation group: 'org.testng', name: 'testng', version: '7.6.1'
// https://mvnrepository.com/artifact/org.apache.poi/poi
implementation group: 'org.apache.poi', name: 'poi', version: '5.2.2'
// https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api
implementation("javax.annotation:javax.annotation-api:1.3.2")
}
Then following popup appeared on vs code.
"Do you want to synchronize the Java classpath/configuration" once and for all? with yes/always/never option
I tried selecting each option in new project. Still after doing gradle build none of dependency downloaded
So if I am writing WebDriver or WebDriverManager I am not getting import option in quick fix

How to repair broken jar built from an IntellIJ gradle Kotlin project?

I try to build a working jar from my project by IntellIJ.
(I add the artifact and build it from the build menu)
I literally can build it as a clean helloworld but as I keep adding the dependencies it breaks.
The built artifact those not find my main class:
Error: Could not find or load main class hu.qlmdc.drp.HelloWorldKt
After a lot of tests I found the exact dependency causing the problem:
"com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8"
Without it the project works but I need the dependency.
What causes this?
How can I repair the artifact?
My gradle file:
plugins {
id "application"
id "java"
id "war"
id "org.jetbrains.kotlin.jvm" version "1.5.0"
}
group 'hu.qlmdc.drp'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
maven { url 'http://repo.jenkins-ci.org/releases/' }
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.5.0'
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.5.0', ext: 'pom'
implementation "io.ktor:ktor-server-core:1.5.4"
implementation "io.ktor:ktor-server-netty:1.5.4"
implementation "io.ktor:ktor-metrics:1.5.4"
implementation "io.ktor:ktor-locations:1.5.4"
implementation "io.ktor:ktor-gson:1.5.4"
implementation "io.ktor:ktor-client-core:1.5.4"
implementation "io.ktor:ktor-client-apache:1.5.4"
implementation "ch.qos.logback:logback-classic:1.2.3"
//implementation 'mysql:mysql-connector-java:8.0.23'
implementation "com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8"
implementation "org.hibernate:hibernate-core:5.4.31.Final"
implementation "org.apache.httpcomponents:httpclient:4.5.13"
implementation "org.apache.httpcomponents:fluent-hc:4.5.13"
// Jenkins plugins
implementation group: 'org.jenkins-ci.plugins', name: 'credentials', version: '2.3.15', ext: 'jar'
implementation group: 'org.jenkins-ci.plugins', name: 'matrix-auth', version: '2.6.6', ext: 'jar'
implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.90', ext: 'jar'
implementation fileTree(dir: 'lib', include: ['*.jar'])
}

How to cache gradle plugin dependencies?

I'm having a gradle script to execute Kotlin code with the gradle application plugin:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.4.10'
id 'application'
}
repositories {
mavenCentral()
}
dependencies {
implementation platform("org.jetbrains.kotlin:kotlin-bom")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// Some other deps
}
sourceSets {
main.kotlin.srcDirs += '.'
}
application {
mainClassName = 'MainKt'
}
What I would like to achieve: During the docker container startup I would like to load all the necessary dependencies with gradle build --build-cache command and be able to run gradle run --offline in the offline mode when the image is ready.
What do I have at the moment: I'm getting No cached version of org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.4.10 available for offline mode. error because plugin dependencies are not being cached during the build phase.
Any ideas what I can do to force gradle to cache not only listed dependencies but also dependencies required by plugins?
Adding the plugin dependency to the dependency list explicitly helped me to resolve this issue:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable" // <-- this solves the problem
// Some other deps
}
I hope this answer will be helpful! Although the use-case is pretty narrow.

How to force downgrade plugin version in in gradle?

So, I have kotlin plugin in my project set to latest stable release 1.3.72 but i have a dependency in which the plugin is defined as id 'org.jetbrains.kotlin.jvm' version 1.+ so it fetches 1.4-M1 which is actually not resolvable and I'm getting the following error:
Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4-M1.
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
This is how i defined version of it in my build.gradle file:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'org.jetbrains.dokka' version '0.10.1'
}
...
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
...
}
Since the org.jetbrains.kotlin:kotlin-stdlib-jdk8 doesn't have 1.4-M1 release gradle could not resolve it. Is there any way to force downgrade the version of this?
I finally found the answer myself, I strictly defined version of org.jetbrains.kotlin:kotlin-stdlib-jdk8 and forced the ktor-dependency for using the defined version:
ext {
ktor_version='1.3.0'
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") {
version {
strictly "1.3.72"
}
because "1.4-M1 is not released"
}
implementation("io.ktor:ktor-server-core:$ktor_version") { force=true }
}