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?
Related
I'm writing Java code in a Jupyter Notebook via IJava . I want to add external dependencies such as OpenCSV. Using gradle, this would normally be incorporated in the build.gradle file via the line
compile 'com.opencsv:opencsv:4.3.2'
How can I add dependencies at runtime via gradle in the Jupyter notebook?
There is the maven magic for this. Since the dependency is on maven central, it is as easy as adding %maven com.opencsv:opencsv:4.3.2 in a cell.
For example
%maven com.opencsv:opencsv:4.3.2
import com.opencsv.CSVReader;
// ...
The name maven is slightly misleading as Maven (or Gradle) is a build tool rather than strictly a dependency manager, but as the dependencies are often resolved from the Maven Central repository the notion of adding a "maven dependency" was a good enough metaphor.
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.
I went through this link to import a gradle project as dependency into another gradle project. Is there a way to include a maven project as dependency into a gradle project?
If that Maven project is built somewhere else and deployed to a Maven repository, you can specify the artifact it produces as a simple compile dependency. If this Maven project is somehow a subproject of a Gradle multi-project build, I suppose you could hack it to work by simply ignoring the Maven POM file and perhaps adding a build.gradle to that project.
To use the solution described on the link that you provided - both projects must be gradle and included in gradle settings. Therefore you can use project closure to compile and depend on the project without building it explicitly.
I am not aware of any way to do this with maven project. I understand you use some maven plugins that you dont want to rewrite in gradle as simply can not find any equivalents etc. Often had that problem.
In this scenario I would suggest to build maven project and depend on a built jar in your gradle project.
Otherwise you could probably amend sourcesets in your gradle project to include maven classes. But I think it would be to complicated.
If I would be you I would turn it into gradle and try to replicate what you had using maven or just build the artifact and depend on it in dependencies closure.
Gradle is not that new anymore and there are many plugins that are superseding old good maven stuff.
I want to build a project which has some external libraries. I included pom.xml file inside intellij and it downloaded all of required dependencies files from maven and put them as external libraries, but my project doesn't recognize them and gives compilation error. IDE screen attached below.
this is one of the compilation errors that I get:
Error:(29, 33) java: package com.google.common.collect does not exist
here is the my external libraries which I think are added correctly.
I don't have maven installed but I think IntelliJ handles it by it self.
Have you tried running mvn clean compile either using Intellij or command line ?
Can I use Gradle to download Java external dependencies without compiling my source code?
The external dependencies have made big changes to package structure since I created my code. I would like to use Gradle to download the new versions and then fix my import statements using the tools in my IDE.
Gradle build seems to be failing without downloading the dependencies because it can't compile my source.
Thanks.
You can't download your dependencies with some custom task, which aims just for that. Dependencies are downloaded on demand, that means, that if you have changed dependencies versions in your gradle build script and then call the task, which have to compile your sources, all the dependencies will be downloaded. Sure, if the imports get wrong, your build will fail and you'll need to update your imports.
So, in other words, if you've changed dependencies versions and then called some task, that compile your sources, your dependencies will be downloaded automatically before the compilation start.
Here is a gradle task to download manually all dependency sources https://gist.github.com/ngtignacio/d0720b7a565729037d0fef1936655793
I adapted the script at https://stackoverflow.com/a/58748741/2439283
It should download all available sources even if the project does not compile.