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'])
}
Related
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
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/"
Non bundled plugins are stored in the repository and can be referenced by groupId:artifactId:versionId but the documentation only says this ambiguous thing about declaring dependencies on bundled plugins:
locate the plugin’s main JAR file containing META-INF/plugin.xml
descriptor with tag (or if not specified).
Okay. Locate it and do what exactly?
My solution was to copy the template for a gradle IntelliJ plugin and copy this example which led me to declare the dependency by plugin name with no version, groupId. In my case I wanted to use classes from the built-in maven plugin so I added this to the plugins = [....]. The plugin will automatically grab the version of that plugin that is in your IntelliJ.
build.gradle
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.26'
}
group 'com.whatever'
version '1.0-SNAPSHOT'
id 'MyPlugin'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime files('maven.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2020.2.2'
plugins = ['maven']
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}
In my gradle file I am trying to use the following to solve another issue. This is my gradle file:
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task copyDependenciesToTarget(type: Copy) {
println 'Copying dependencies to target...'
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
}
build.dependsOn(copyDependenciesToTarget)
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
The problem are is this:
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
When I run the application I get this Exception:
org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated cannot be cast to org.gradle.api.internal.file.copy.CopySpecInternal
Main problem is, I have no idea how to fix this error, I simply want my project to create a JAR file that works with JDBC, using this gradle code seems to be a solution for that issue, but now I have run into another problem, yet again.
Please let me know if you require any additional information and thank you in advance. Literally, I cant even. This problem.
EDIT
As stated in the comments. My project runs fine when I run it through the IDE. There is an issue when I create a JAR file using gradle. The bare gradle file that IntelliJ created when I started the gradle project follows (Added the jar config so my Main class would be picked up):
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
When I execute my app from terminal after the JAR has been created (keeping in mind there are no issues when hitting run in the IDE) with java -jar myAppName.jar:
java.lang.ClassNotFoundException: org.sqlite.JDBC
NOTE: Usually I get a full stack running a java app, but in this case the above is the only output.
I am using this JAR for my sqlite needs:
sqlite-jdbc-3.15.1
As a test I commented out the Sqlite usage in my application and the JAR file worked fine. My GUI was displayed and everything went as expected (all things considered). The JAR stops working when I add the sqlite JAR file usage (code). Added it the same as my other libs (like retrofit), so this seems to be quite a strange issue.
Please let me know if I have explained the issue correctly?
After I added copyBootstrap to build.gradle I am getting the next error when try to run the build task:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project '.
Cannot change dependencies of configuration ':providedCompile' after it has been included in dependency resolution.
How could this issue be solved? I have searched on Internet but no solutions were found. I got the copyBootstrap task from this link. Their goal is to extract all content from org.webjars group jars to a specific path.
I am using Gradle 3.2 and Intellij IDEA 2016.2.5
//group 'org'
//version '1.0-SNAPSHOT'
task wrapper(type: Wrapper) {
gradleVersion = '3.2'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.4.0'
}
}
repositories {
mavenCentral()
jcenter()
}
//apply plugin: 'java'
//apply plugin: 'eclipse-wtp'
//apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
//compile group: 'org.akhikhl.gretty', name: 'gretty', version: '1.4.0'
// ********************************************************************************************************
// SPRING FRAMEWORK, ORM Y H2DB
// ********************************************************************************************************
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.4.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.3.4.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version: '4.3.4.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.3.Final'
// ********************************************************************************************************
// JACKSON DATABIND
// ********************************************************************************************************
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.4'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.4'
// ********************************************************************************************************
// THYMELEAF
// ********************************************************************************************************
compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: '3.0.2.RELEASE'
// ********************************************************************************************************
// SERVLET
// ********************************************************************************************************
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
// ********************************************************************************************************
// MYSQL CONNECTOR
// ********************************************************************************************************
//compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5' issues with time zone
compile 'mysql:mysql-connector-java:5.1.6'
// ********************************************************************************************************
// WEB RESOURCES
// ********************************************************************************************************
compile group: 'org.webjars', name: 'angularjs', version: '1.5.8'
compile group: 'org.webjars', name: 'jquery', version: '2.1.4'
compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'
compile group: 'org.webjars', name: 'jquery-ui', version: '1.12.1'
compile group: 'org.webjars', name: 'modernizr', version: '2.8.3'
// ********************************************************************************************************
// JUNIT AND SPRING TEST
// ********************************************************************************************************
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.4.RELEASE'
// ********************************************************************************************************
// GOOGLE DRIVE API
// ********************************************************************************************************
compile group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0'
compile group: 'com.google.apis', name: 'google-api-services-drive', version: 'v2-rev245-1.22.0'
compile group: 'com.google.api-client', name: 'google-api-client-java6', version: '1.22.0'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0'
// ********************************************************************************************************
// DROPBOX API
// ********************************************************************************************************
compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '1.8.2'
// ********************************************************************************************************
// TWITTER API
// ********************************************************************************************************
compile group: 'org.twitter4j', name: 'twitter4j-core', version: '4.0.5'
// compile group: 'org.slf4j', name: 'slf4j-mylearn.api', version: '1.7.21'
// compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
// compile files("twitter/main/webapp/") // add this path as a classpath
}
task copyBootstrap(type: Copy) {
into "$buildDir/static_resources"
configurations.compile
.files({ it.group.equals("org.webjars")})
.each {
from zipTree(it)
}
}
//build.dependsOn(copyBootstrap)
task copyToLib2(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}
war {
archiveName = 'ROOT.war'
destinationDir = file('webapps')
}
// ********************************************************************************************************
// GRETTY SETTINGS
// ********************************************************************************************************
/* Change context path (base url). otherwise defaults to name of project */
gretty {
port = 8081
contextPath = ''
}
This problem seems to be related to the org.akhikhl.gretty plugin you are trying to use. If I try to build a project using the above gradle file I get the following output:
C:\ws\PLAYGROUND\test123>gradle wrapper --stacktrace
Changed dependencies of configuration ':providedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is cheduled to be removed in Gradle 3.0.
Changed dependencies of parent of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed strategy of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
Changed dependencies of configuration ':grettyProvidedCompile' after it has been included in dependency resolution. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0.
⋮
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'test123'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:79)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:74)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
⋮
Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of configuration ':compile' after it has been resolved.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:578)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$2.run(DefaultConfiguration.java:137)
⋮
at org.akhikhl.gretty.GrettyPlugin$_addDependencies_closure11.doCall(GrettyPlugin.groovy:130)
⋮
That is the gretty plugin seems to use functionality that has been removed with gradle 3.0
There is issue #306 that has been reported a short time ago which describes pretty much your problem.
Given the number of open issues for such a small project and the lack of activity on the issues, I don't think this plugin is much of a help and you will probably be better off using something different.