mvn dependency not recognised after dependency version change - java

I have a custom dependency for my project, api-client. This dependency is used to connect among multiple modules within my project.
The problem is, if I make any changes in my api-client dependency and I produce a .jar file using the below command:
mvn install -Dmaven.test.skip=true
I will place that .jar file in my .m2 repository manually. Afterwards, if I try to run other modules which depends on api-client, those modules
would throw lots of compilation errors. (Previously, all ran successfully.)
Some of the sample errors are as follows:
[ERROR] /C:/Local/core/src/main/java/com/core/service/impl/DBSClaimServiceImpl.java:[33,39] C:\Local\core\src\main\java\com\core\service\impl\DBSClaimServiceImpl.java:33: package org.apache.commons.lang3 does not exist
[ERROR] /C:/Local/core/src/main/java/com/core/service/impl/DBSClaimServiceImpl.java:[33,1] C:\Local\core\src\main\java\com\core\service\impl\DBSClaimServiceImpl.java:33: static import only from classes and interfaces
[ERROR] /C:/Local/core/src/main/java/com/core/model/Dealer.java:[9,39] C:\Local\core\src\main\java\com\core\model\Dealer.java:9: package org.apache.commons.lang3 does not exist
[ERROR] /C:/Local/core/src/main/java/com/core/model/Dealer.java:[9,1] C:\Local\core\src\main\java\com\core\model\Dealer.java:9: static import only from classes and interfaces
[ERROR] /C:/Local/core/src/main/java/com/core/resource/settlement/flatFile/RecordType1ClaimInformation.java:[10,39] C:\Local\core\src\main\java\com\core\resource\settlement\flatFile\RecordType1ClaimInformation.java:10: package org.apache.commons.lang3 does not exist
All the packages are available in my local repository, but still, it is not recognising them. I am unsure what exactly the problem is here.
Below please find entries that I have in one of the module:
<api.version>1.0.245</api.version>
<api.client.version>1.0.292</api.client.version>
The problem started once I changed the above version (api.client.version). After that, an old version also throws the same error.

To resolve transitive dependencies, other modules do not just need the api-client.jar, but also a generated pom.xml which declares what other jars are needed to use api-client.jar.
There are multiple ways to fix this, but the description of your environment is not detailed enough to tell how best to fix this.

Related

Kotlin compile works, mvn compile and intellij run-app does not

I'm having a very odd issue which I cannot explain.
I've made an artifact using gitlab ci, which I'm now importing as a dependency in another project using maven.
When I import this into the new project, I get some very strange behaviour in regards to the classes in the imported dependency. These behaviours are as follows:
In Java files (Test.java), the package is found and Intellij reports no issues. I can even navigate to the source code in the library.
In Kotlin files, Intellij complains that this package cannot be found. I can't navigate to the source code as the IDE says "unresolved reference". If I do a maven artifact search, it is found but adding it makes no difference as the dependency is already in my project.
maven compile/package also complains that this package cannot be found
The dependency is definitely present:
I've tried the following:
Reimporting maven projects
Invalidating caches
Changing java versions, 8 - 11
The artifact is written in java 11 if that makes any difference.
Please help, this is driving me crazy.
Thanks to those that answered!
After a long 24 hours of debugging, it turns out the issue is related to how intellij & maven look for packages in dependencies.
I was compiling with the spring-boot-maven-plugin which was building the jar with a top BOOT-INF directory, and the package structure below this.
This meant both intellij and maven were confused as they seemed to be able to find the package but not build it.
I've since removed the plugin and left now just compile with the kotlin-maven-plugin which has the package structure at the top level of the jar.
Now when I import into a project, the project can find and compile this dependency.

Maven build failure from missing tycho dependency?

I'm attempting to build two Maven projects from Eclipse. One project constitutes a set of dependencies and libraries to be used for the other project which contains all of my source code. Both are configured as Maven projects using Tycho 1.0.0 .
I have a parent POM file that contains three modules: a folder containing my target file, the plugin containing the dependencies and the plugin that contains the source code. When trying to maven build on the parent POM, I get the following error:
Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile (default-compile) on project com.ericsson.cd-editor.ui: Execution default-compile of goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile failed: A required class was missing while executing org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile: freemarker/template/Configuration
Gonna post the full error log in pastebin since it's diffcult to read in a Stack Overflow post:
http://pastebin.com/EYnsqvpJ
Here is my parent POM file:
http://pastebin.com/wSAtwspV
I've been told by a colleague of mine that the reason this might be happening is that this dependency might be used by Tycho and cannot be found. The freemarker package is however available in my .m2/repository/.
It's really hard to tell where the error might be.
First, make sure the jar you have in your m2 archive actually contains the class the compiler is looking for.
You could check whether you dependencies are in the central maven repository, instead of making a project containing them.
Does the project that needs all the dependencies state them explicitly, e.g., in feature.xml or Manifest.mf? Otherwise tycho will not load them, even if they are accessible to maven.
Posting the pom.xml files for the modules might be helpful. Hope you'll figure it out :)

QueryDsl error. Q classes not generated

I try to generate query type classes (e.g. QUser) but got errors...
You can find my source code here: https://github.com/TheNakedMan/remindme.server/
I'am working with IntelliJ IDEA, and it seems like I have working plugin.
Help me, please.
Log message:
/remindme.server/src/main/java/com/qoobico/remindme/server/repository/UserRepository.java
Error:(21, 126) java: cannot find symbol symbol: class QUser
Error:(25, 62) java: cannot find symbol symbol: class QUser
location: interface
com.qoobico.remindme.server.repository.UserRepository
UPDATE:
After LifeCycle->clean and run apt:process in IntelliJ, I have this error:
[ERROR] Failed to execute goal on project com.qoobico.remindme.server:
Could not resolve dependencies for project
com.qoobico.remindme.server:com.qoobico.remindme.server:war:1.0-SNAPSHOT:
Could not find artifact
com.qoobico.remindme.server:com.qoobico.remindme.server:jar:1.0-SNAPSHOT
In your sources you did not import the generated classes, for instance:
import com.qoobico.remindme.server.entity.QUser;
If you want to generate the classes without compile and/or install the package use the maven goal apt:process.
You can use IntelliJ to start such a maven goal, use the Maven Projects window. The window will show you all available goals.
On the commandline you could use the mvn cli, which can be downloaded here.
Hint: the command from the help plugin mvn help:describe -Dplugin=com.mysema.maven:apt-maven-plugin will show you a list of all available apt-maven-plugin goals.
You configured the outputDirectory to: target/generated-sources/java
To let your IDE find that classes, put them into your class path. Some IDEs like IntelliJ will do this automatically for maven projects, because that folder is the default.

Is there a Maven plugin or configuration that will verify the Java package declaration matches the source directory?

I've ran into an issue with Maven a few times now where the build does not fail if there's an inconsistency between the package declaration and the path of the source file. From other Stackoverflow questions, there are several examples that shows Eclipse catches this type of error no problem and explains why Maven doesn't:
Eclipse says package declaration does not match expected package ""
Eclipse: The declared package does not match the expected package
Maven + Java package declaration
There are a few different issue that can arise when Maven doesn't catch this inconsistency including run-time failures to load classes or unit tests omitted from a build without flagging any errors.
Although Maven doesn't catch this with the compiler, is there any Maven plugin out there that will validate the package name to the source path? Or possibly some other configuration value that can be set in the pom.xml or settings.xml to get Maven to verify these are consistent?

How to find which maven dependencies are missing

I have a web project and a pom.xml file. It has enough dependencies to compile and package but not enough to start the project. In my IDE it's shown that everything is ok, but when a start the application it has errors. When i add external pom.xml from another app, my application launches.
So is there any way i can find out which dependencies are missing and how in future i can determine which dependencies are needed for using this or that?
You can use mvn dependency:analyze for determining which dependencies are used and declared or used and undeclared or unused and declared.
For more information refer to: http://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html.
Hope this helps.
There's no maven command to accomplish this. You need to check which classes are causing NoClassDefFoundError, figure out the dependency (Google) - which JARs they are shipped in, and add them with the runtime scope in your pom.xml.
In web projects specifically you oftentimes compile against servlets or Java EE specification JARs (they would only contain interfaces), but you need actual implementation JARs to be present in runtime. These JARs are typically and presumed to be available in the container you are running in (like Tomcat or JBoss), in this case they would be marked as provided scope in your pom.xml.
You need to check the NoClassDefFoundError in your output logs and add dependencies accordingly.
The best resource to search for missing dependencies is Maven Central Repository
To get a detailed debug log of your build, use -X in the command line.
You can check The dependency tree of your project by following command - mvn dependency:tree. This will only list the information about the deoendencies listed in your pom.xml More on it here
should be able to do it with :
maven dependency resolve

Categories