new dependency not recognised by Maven - java

Using maven version 3.6.3 and JDK version "openjdk-17"
I've tried using Maven's dependencies so I could use the xstream library in my project. Following a guide I added com.thoughtworks.xstream to my pom.xml file:
I then tried to use xstream, but intellij couldn't resolve "XStream" even though it seems to work for JavaFX just fine. This code does not compile.
EDIT: I loaded a new project, where I used, what I believe to be, up to date versions. Maven 3.8.1, the latest intellij version, and everything else (JDK, openjfx) at version 17.0.2 yet when I try to use "XStream" in my project code (after reloading the maven project) it says "Cannot resolve symbol XStream"
Edit 2:
I added junit to the dependencies, it works. I add Gson to the dependencies. It doesn't work.

I figured out that in the "modules-info.java" file, "requires xstream" is needed. That is all

One of the following may solve your problem:
These are based on my previous experiences.
because may be auto import disabled. re Import maven project.(intellij: press Ctrl+Shift+A then actions - input "reload" find "Reload All Maven Projects").
in my experience, sometimes it does happen that the dependency is not fully received. remove xstream special version folder from .m2 (com->thoughtworks->xstream) and repeat step 1.
maybe repository not valid. check repository source in file settings.xml in .m2 (if exist) or replace to other source.
invalid cache and restart (intellij: file-> invalid caches/restart). This has solved my problem several times.
Your access to the site or repository may be closed. check network policy or use vpn (Poor probability)

Related

Maven: How to stop using old version of dependency?

In my Java Maven Project I can see the following 2 versions of the one dependency (apache httpcomponents):
How can I ensure that only the newest version (4.5.2) is used in my project?
I cannot even find 4.2.1 declared anywhere within my pom.xml files to remove it.
There should never be two versions of the same dependency for a given project.
So either your IDE shows something wrong here or you did not mvn clean before the build so that old and new dependencies mixed.
Maven will always take only one version. Unfortunately, you cannot tell Maven to take the latest one, but it will always take the nearest one in the dependency tree.
If you want to set the version for a specific dependency, use <dependencyManagement>.
Based on your screenshot you're using IntelliJ. And I have to agree that this view is kind of confusing. In the Project-tab you'll External Libraries which contain all dependencies of all projects in this tab. For that reason dependencies might appear with different versions.
In the Maven-tab (right hand side) you can see the dependency-tree per project. First you'll see the direct dependencies, which you can expand to see the next level of dependencies. AFAIK there's no complete dependency list available in IntelliJ, as one would see with Eclipse.
That's the view of IDE, it shows all the using or used library in your project. Once you point your pom.xml to the new version and rebuild your project, the new version will be used.
In Intellj, you can select: Menu -> File -> Invalidate Caches/Restart to update it. If that won't help, start new project from your existing pom.xml file

Compilation error occurs if jars are added manually in Intellij

I am using Maven in my project, and for some reasons, some additional jars should be added manually (I have followed the step like Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project).
The package can be imported successfully. However, the compilation error happens, which indicates the package does not exist and cannot find the symbol of the used object.
I have tried the following tips but it remain unchanged:
Invalid caches / restarts
reimport
delete .idea file and .iml file
The scenario is quit similar to this one : https://intellij-support.jetbrains.com/hc/en-us/community/posts/206821195--beginner-question-including-external-jar-compile-error.
Please see the following sample images. It may run successfully but cannot be compiled well.
The reason is that when you add a library manually via IntelliJ, only IntelliJ knows about them and when you compile your code using Maven, it can't be find by Maven because Maven only searches for dependencies you defined in pom.xml.
You should install your libraries in your (at least) local maven repository and add them as a normal dependency in your pom.xml. Then you don't need to add them manually in IntelliJ.
You should follow the steps mentioned at Guide to installing 3rd party JARs
Update:
Also you should note that if you're working as a team, you should install this on the local maven repository of all developers (which is not practical). The best solution is to install a Maven repository (e.g. Nexus, Artifactory or Archiva) in a server on your local network and upload your private jar files on those servers. Then all developers can define the address of the local Maven repository server in their local Maven settings and use artifacts/libraries from that servers. Plus it works as a local cache/proxy to fetch any Maven artifacts and prevents unnecessary calls to public maven repositories.

IntelliJ SBT project cannot resolve SBT symbols

I'm banging my head against the wall on this one.
Trying to open a cloned git SBT project at work. It is a combined Java and Scala Play project, with scala 2.11.1, SBT 0.13.6, and Play 2.5.
I use IntelliJ to import project from the cloned repo, with JDK 1.8, and all download and SBT checkboxes checked, and then run either SBT refresh, or reload from SBT shell.
After doing so, all SBT and Play code on both build.sbt and plugins.sbt is painted red, as in "cannot resolve symbol".
Looking at Intellij poroject structure, I have JDK1.8 on the SDK tab, and scala-sdk-2.11 on the Global Libraries tab. SBT and Scala plugins are installed and enabled.
SBT refresh fails on the following Play dependency, which could be the reason for the above symptom, since the SBT build does not complete:
unresolved dependency:
com.typesafe.play.plugins#play-statsd_2.11;2.3.0: not found
The dependency does exist:
http://dl.bintray.com/typesafe/maven-releases/com/typesafe/play/plugins/play-statsd_2.11/2.3.0/
What am I doing wrong?
Turns out the problem is on the typesafe side, not on my env.
All typesafe dependencies on the project are resolved as expected, except for play-statsd.
I manually added this dependency to my ivy cache, and now everything works fine.
It was a hard one to isolate, because apparently everybody here already have the dependency on their caches, so seems like their updates work well...
If anyone has the same problem, fetch the dependency from the bintray repository, and manually add it to your ivy cache, e.g.
~/.ivy2/cache/com.typesafe.play.plugins/play-statsd_2.11
The github play-plugins repository has been archived, so I can't open an issue, and don'y know if anyone will take care of it anyway.
Unresolved dependency error usually related with Scala version that you are using.
Here is Play 2.3.x documentation.
https://www.playframework.com/documentation/2.3.x/Migration22#Update-Scala-version
If you are able to use Play 2.7.x, your issue will be fixed.
Could you please add Play StatsD dependency in build.sbt as below and check once.
"com.typesafe.play.plugins" %% "play-statsd" % "2.3.0"
You should add maven-releases resolver:
resolvers += "Typesafe Resolver" at "http://repo.typesafe.com/typesafe/maven-releases/"

How to resolve missing artifact error when using Eclipse AWS plugin?

I am using the aws Java plugin for Eclipse. I didn't have any issues during the installation process but after I used the plugin to create a sample DynamoDB project, I got this error
Missing artifact com.amazonaws:aws-java-sdk-cl....watchmetris.jar:1.11.123(click for 156 more...).
clicking didn't do anything.
I thought the error was due to the fact that I didn't install that jar during the installation process - I only installed "AWS Toolkit for Eclipse".
I went back into Eclipse and installed every non optional plugin from the aws(see below)
After I restarted Eclipse and tried creating my DynamoDB project again, I get a different failed to read artifact descriptor error(see below)
Has anyone experienced this issue before or know what the solution is? Elastic load balancer should be apart of AWS Toolkit which I installed. I've tried removing and reinstalling the aws plugin but I'am still getting missing artifact errors. I've looked at other threads on AWS plugin for Eclipse as well.
For anyone dealing with this issue with this issue, I got it to work! I can't really explain why it works though - maybe Maven's way of resetting some setting.
What I did was go inside pom.xml, the configuration file for Maven, and into the Dependencies tab. This is what I saw
I reasoned that the missing artifact was in the aws-java-sdk jar so I removed it. I then deleted the project from disk and created a new one. The new project came with the correct dependencies and no compiler errors!
The problem is not your AWS Toolkit, it's a problem of your Maven. Please try to create a project with Maven to check if Maven's setting is correct. If Maven is correct, please see your pom file in XML and check the dependency is correct? If you cannot create Maven project, it's means that your Maven setting is wrong somewhere!
I received a similar error "failure to transfer com.amazonaws:aws-java-sdk ...". The pom resolution could work, but here's another solution. So, when you start an aws project for the first time, certain artifacts necessary for maven are stored under .m2\repository\com\amazonaws.
What happened to me was that when I deleted one of my aws projects, I also deleted the resources being referred to which was somewhere in the aforementioned directory. And because the directory existed, eclipse's aws toolkit didn't bother downloading it again. I solved it by just deleting the $home.m2\repository\com\amazonaws directory. So next time I created a new aws project, it had to download all the artifacts.

Why can I not access all plugins in my target definition?

I have a problem concerning target definitions in Eclipse. I want to use plugin version 1.0.0, which is in my target platform definition, while I have the plugin project in my workspace with version 1.0.2. For all other plugins in my target definition, everything works as expected (which I see because an error gets flagged if something's missing), but this specific one, Eclipse does not make available to my projects. Only the plugin version 1.0.2 is. The plugin is not set as a singleton.
Why is this and how can I resolve this problem?
I figured out that I can access the right version when I close the project that contains the wrong one - but this is awkward, is there another way?
It seems that it's actually not an eclipse-specific problem, it fails also when building on the command line through maven/tycho. Specifically, my target platform is the Juno Release. Are there plugins that, while part of a feature, are not made available to other bundles? I know the plugin is there, but neither tycho nor Eclipse want to make it available to me.
Maybe I should also say it fails at compile time.
While, as I said, there exist workarounds for the problem, I still would like to have a "nice" solution to this problem. You can check out the project together with the target definition at https://github.com/kutschkem/Jayes
You may also need to check out and build this project first:
git clone http://git.eclipse.org/gitroot/recommenders/org.eclipse.recommenders.git
After setting the target platform, try building something with Jayes 1.0.0 (which is in the target platform) instead of Jayes 1.0.2 (which is in your workspace). You can also try to build with maven, it doesn't work as well.
Known workarounds:
Close the Jayes 1.0.2 project. Then, eclipse lets you use Jayes 1.0.0
For running an (OSGi) application, you can choose which bundles are loaded. You can choose version 1.0.0 manually there
Using a product definition, you can access the same runtime configuration as for workaround 2
If someone finds a workaround for maven, I'd be happy to know about it.
Maybe you have set your plugin to be singleton, so there will only be one instance for the bundle with a specific id.
You can change this by remove the "singleton:=true" in your MANIFEST.MF.
Bundle-SymbolicName: org.eclipse.xxx; singleton:=true
Or, you could remove the 1.0.2 version plugin from the run configuration when start running. click run --> run configuration to open the run configuration dialgo, switch to 'plugins' tab, here you can select which of these plugins you want to use .
I think you have already tried the following, but a reload of the target platform might help.
Also, what does your feature.xml file specify for version of that plugin?

Categories

Resources