IntelliJ IDEA using JavaScript "version" of dependency specified in Gradle build file? - java

This issue just recently (past couple days) started occurring on one of my development machines.
I'm using Eclipse's Vert.x dependency for a web project:
build.gradle
dependencies {
...
// Kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
// Vert.x for web framework
compile group: 'io.vertx', name: 'vertx-core', version: '3.4.2'
compile group: 'io.vertx', name: 'vertx-web', version: '3.4.2'
...
}
This has worked fine in the past - I think the triggering action was my upgrading to IntelliJ 2017.2.2, but now:
IntelliJ cannot resolve any of the -web imports:
If I examine the Dependencies list for my Module, the JavaScript version of the dependency is shown?
How did this happen, and how can I make sure it's properly recognized as a Java dependency?
Edit: Sample project available here: https://youtrack.jetbrains.com/issue/IDEA-177950

This is a bug in the Kotlin plugin which is fixed in version 1.1.4-2. After you update the plugin, you need to delete the incorrect libraries and reimport your project from Gradle to have your project fixed.

If you face such problems, the first two things you always can do is:
(in IntellJ) File > Invalidate Caches/Restart
(in IntellJ's Gradle Bar) Press button for Refresh all gradle dependencies
If this doesn't help, please check if ./gradlew clean testClasses succeeds or also fails with such an error.

Related

Importing JavaFlacEncoder from Maven

I'm trying to load the JFE library from maven but when I build my gradle project it's throwing symbol errors. In my IDE as well, I'm getting unrecognised symbol errors.
enter image description here
I've tried using both:
compile group: 'net.sourceforge.javaflacencoder', name: 'java-flac-encoder', version: '0.3.7'
and
implementation 'net.sourceforge.javaflacencoder:java-flac-encoder:0.3.7'
I tried downloading the latest version available on the source forge and adding it as a dependency using my IDE (IntelliJ). This worked, but when I built it because it's a raw jar dependency, instead of a gradle dependency, the gradle build fails.
I want my project to be portable, so I want it to rely on gradle dependencies instead of jar dependencies. Why is this gradle dependency not working?

How do I use BouncyCastleProvider in Java 11

I have been trying to find a way to BouncyCastleProvider in Java 11 from openjdk. Since there is no ext folder, I can't figure out where to put the jar file. I am using gradle build on MacOS Catalina. It will really help if someone can help me out on this.
I am getting the following error while running gradle build. I have dependency mentioned in gradle as well.
java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
You can use the way you import all your other gradle dependencies.
For example with the dependency:
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.64'
Taken from:
https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on/1.64
(Where you can find other versions if you need them)
If you're unsure how to import gradle dependencies I'd suggest searching Stackoverflow, as I'm sure that been asked many times before.
For example:
How to import external dependencies in gradle?
EDIT: You added another error. Could be the path of the jar needs to be added / classpath.
If you want to add the JAR to your ide, which I guess is Gradle Build Tool if I understood you right. They speak of how to do it here:
How to add local .jar file dependency to build.gradle file?

Installing Mockito using Gradle

I have installed Gradle by adding the path to it into the system variables. I am quite new to Java and this is the first time that I am trying to install an external library for it. On the Mockito web-page, they say that one can:
Declare a dependency on “mockito-core” library using your favorite
build system. With Gradle one can do:
repositories { jcenter() }
dependencies { testCompile "org.mockito:mockito-core:1.+" }
So I have no idea what it means. I changed the directory in cmd to the Gradle folder and tried to execute these commands, but that is not how one is supposed to do it. Can you give me a hand here?
You have to create a build.gradle file where you can insert the dependency. I recommend using an ide like eclipse or IntelliJ which can generate a gradle project for you so you don't have to do this manually. Just install the corresponding Gradle Plugin. This also makes sure you have a correct project structure.

Issues with Dependency Libraries in Eclipse Using Gradle

I a newbie in Gradle and trying to find my way around it but facing some issues that needs to be resolved before i can proceed my Gradle tutorials.
At the moment i have compiled the app from the command prompt and seems to be working.
The issues i have now is that i can't see the dependencies (spring libraries) that Gradle has downloaded in Eclipse. If i look into the "Project and External Dependencies" folder in eclipse under the Gradle project i have created, i can't see the spring libraries there. For instance in Maven, the moment you add a dependency and save the POM file, the dependencies are added to the library instantly. Because of this issue red-error-markers appear in the source codes that are using the spring libraries though the application runs perfect from the command line.
How do i fix this problem? Does Gradle put the libraries somewhere?
My buld.gradle file is
apply plugin: 'java'
apply plugin: 'application'
mainClassName = System.getProperty("mainClass")
repositories {
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.14'
testCompile 'junit:junit:4.12'
compile 'org.springframework:spring-context:4.0.5.RELEASE'
}
thanks.
Extra question :: is there a way to let Gradle run in eclipse so that the output of my application is displayed in the eclipse console?

mockito in gradle not working for java project

I have a basic java project and I want to run tests using Mockito (since I use it at work and it's easy). So I referred to this link and added the following to my build.gradle
dependencies {
testCompile 'junit:junit:4.11'
testCompile "org.mockito:mockito-core:1.+"
}
Even though I think mavenCentral() should be enough, I went ahead and added these to my repositories list
repositories {
mavenLocal()
jcenter()
mavenCentral()
}
The ./gradlew clean build runs perfectly fine, but when I try to add the import for Mockito it doesn't get it. And my External Libraries folder in the project doesn't have the Mockito jar. I even tried using mavenLocal() in the hope that it'll pick it up from my local .m2 directory, but it doesn't. I've been looking around and trying out all combinations for 2 hours now with absolutely no result. I don't want to add the jar to the project. I want to let gradle pull it from the central repo and compile it.
Thanks for any help in advance.
I found the answer here Apparently clicking on that refresh button refreshes the dependencies. Else right click on module -> Open Module settings -> Go to Dependencies tab and add your dependency either from your local m2 folder or provide the maven central URL for the dependency.
I was too used to Eclipse doing stuff for me I guess. :)
Is this in Eclipse? If so, right-click on the project and go gradle > Update All (I think it is - I don't have open at moment and don't think about it any more). This will update the dependencies.
If you are referring those libraries other than test package, that is main package you will get this error.
Because you provided scope testCompile in build.gradle, so these libraries are available only in test package.
So, change testCompile to compile in build.gradle.

Categories

Resources