Maven can't find a module - java

I've been trying for the last few weeks at this point to get Maven to compile my project and I am so desperate
I am running the following maven command on the root directory:
mvn clean verify -fae -X
And I am getting the following output: log on Pastebin
This clearly means that it cannot find the module that it has already identified, during compile (meaning any goal that includes compile will throw the same error). IntelliJ could even find the source of the module (with find usages) in the MAVEN LOCAL REPO as a compiled JAR, which baffles me because maven doesn't seem to want to figure that one out and now after renaming it can find the sources in this project too, so I don't know where it could be going wrong at all.
I can't provide any relevant code, because I have no clue where the issue might lie. All of my code can be found on my GitHub here, in the IerisLib repository on the experimental branch.
I am extremely frustrated with this issue and at this point I don't know what to do. I have attempted:
Deleting all and cloning again, changing the module's names twice, rewriting the module-info.java files and just playing around with Maven command parameters(that's how I came up with -fae -X instead of just mvn clean verify).
I'm running Maven 3.8.5
Please, any help is appreciated

Related

Maven site fails while building javadoc

I try to build a site for my minecraft plugin but it fails during javadoc generation. I have my pom.xml and the log in this gist.
When I run mvn clean site it fails while generating javadoc because it does not find the dependencies used in my program. The problem is, that these dependencies are usually provided by the server, which tries to run the plugin so it does not make any sense to compile these dependencies. For some dependencies it is even forbidden to compile them. For example the spigot-api, which is part of the io.papermc.paper:paper-api-dependency.
And the weird thing is, it works just fine in IntelliJ. When I run the mvn clean site-command in IntelliJ using a run configuration it works just fine.
I already tried the additionalDependencies option but it did not improve the result.
I could stop it from failing the build by setting failOnError and failOnWarning to false but I still don't want these errors in my log.
Any ideas how to fix it?
Sincerely yours,
Trqhxrd

situations where clean install is a must not just install?

I have a question which is pretty straight forward, but hard to find an exact answer.
When we are using mvn build, what are the exact situation where we must go for clean install in order to see latest code changes in our built artifact. i.e. just install would not do that for us.
Thanks in advance.
Basically
mvn clean install
is same as
mvn clean && mvn install
so as to answer your question, its required when cleaning the files and directories generated by Maven is the primary requirement prior to doing another install.
Related to the changes in code, I would assume this is more of cleaning the target folder generated by Maven, hence mostly the files compiled would be overwritten when there is not much of a change.
In cases where one has removed/refactored a class from the previous build. There might be references still left if you don't clean and that would get packaged into the jar created thereafter.
From the official documentation(formatting mine) shared by ernest,
But if we try to build the project with mvn install without any clean lifecycle, then we see 2 bugs
the maven build still succeeds to compile the project maven even
generates a jar which contains broken classes
moduleB does not get recompiled and is thus broken as well.
Also, a preferably suggested way is to instead use
mvn verify

IntelliJ Compilation Error zip END header not found

The Issue
I am unable to compile Java code for an imported Eclipse project on IntelliJ build 182.4505.22 on Java 9 and 10. The following error is displayed when compiling the module, or any individual file:
Error:(1, 1) java: cannot access edu.wit.cs.comp2000
zip END header not found
Details
The structure of the project is as follows:
The full compile-time output is as follows:
Already Attempted
I have reviewed posts here and here, which do not provide any relevant details.
I have attempted compiling on both Java 9 and 10, which makes no difference.
I have written a main method into LinkedBag and attempted to run that independent of JUnit, which results in the same error.
IntelliJ is not correctly displaying the testing icons in my test class, so I suspect that JUnit (or lack of JUnit) is the cause of the issue, however I am unsure how to proceed. Compiling works for other projects (without JUnit tests) just fine.
Updates
The code seems to compile and test as expected on Java 1.8 without issue. Switching to Java 9 or 10 causes the above issue every time. I am beginning to suspect that one of my instructor's dependencies requires Java 1.8 specifically, however I would still like to use newer versions of Java if anyone might have a solution.
As mentioned above, just delete the corrupted cache and restart Intellij.
Running gradle in the commandline can help knowing what you should delete. For instance:
$ ./gradlew --version
Could not unzip /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb/gradle-5.6.2-all.zip to /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb.
Reason: error in opening zip file
and after deleting the folder /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb the problem was solved:
$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip
......
We had this issue when internet connection dropped while Idea was downloading project dependencies. We solved it by deleting the corrupted file from cache. Cache location depends on your build tool, e. g. for Maven it's in ~/.mvn, for Gradle it's in ~/.gradle.
In my case, it was: /.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar
I just removed it and I was able to compile my code.
Just pay attention to the .jar file in your case it's giving an error. Just remove it and you are good to go.
I Had Similar issue in my mac.I just deleted .m2 repository and did maven clean install again worked.
Instead of deleting your whole maven repository you can scan through it locally to find the bad jar file using GNU utils
find <maven-repository-dir> -type f -name "*.jar" -exec zip -T {} \; grep -v OK
I got this error
[ERROR] error reading /Users/username/.m2/repository/io/confluent/common-config/5.5.1/common-config-5.5.1.jar; zip END header not found
I don't know why the jar was corrupted but the error went away when I replaced the jar with my colleagues jar file. Fixing the error temporarily.
In my case, the gradle version of the project was 6.2.2 and the 6.4.1(system default gradle) path was provided in the Intellij gradle settings.
This issue appeared suddenly though. I was working on this project for a long time without any issues. I am not quite sure as to what triggered this issue. The gradle default version package was fine as the gradle build was fine from command line. :)
Referred to suggestions from here
Any one of the below solved the issue on my system:
Provide the path to project gradle version, in gradle settings.
or
Change the 'distributionUrl' value in your gradle-wrapper.properties to have 'all' instead of 'bin'. And also make sure you have gradle-wrapper.properties configured in your intellij gradle settings.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip
This can also occurs when you use a dependency that requires to be of type pom (to transitively add all dependencies, useful for BOMs) but without specifying it.
For example if you have a Spring Boot project and use that starter :
<dependency>
<groupId>org.zkoss.zkspringboot</groupId>
<artifactId>zkspringboot-starter</artifactId>
<version>${zkspringboot.version}</version>
</dependency>
Then mvn clean package will give you the following error :
Error: java: cannot access com.example.myproject
And running the app will result in the following error :
java: error reading ...\.m2\repository\org\zkoss\zkspringboot\zkspringboot-starter\2.3.0\zkspringboot-starter-2.3.0.jar;
zip END header not found
because it should not perform any packaging.
Adding the pom packaging type fixes the problem, so that it keeps the artifact simply as a descriptor of dependency versions :
<dependency>
<groupId>org.zkoss.zkspringboot</groupId>
<artifactId>zkspringboot-starter</artifactId>
<version>${zkspringboot.version}</version>
<type>pom</type>
</dependency>
Tweak file watching settings did the trick for me.
For Ubuntu/Mac Run these 2 commands.
sudo echo "fs.inotify.max_user_watches = 524288" | sudo tee /etc/sysctl.d/40-idea.conf
sudo sysctl -p --system
I had a similar issue when I used the dependency thymeleaf-extras-springsecurity4 from org.thymeleaf.extras in a spring boot application.
Updating the dependency to the latest version helped.

A class is looking for methods of another class in the maven repository instead of the source code

I have two (really more, but we are interested in these two now) projects in the Eclipse workspace. One of them has got a class A that just obtained several new static methods.
I want another one class B, in another project, to call these methods. But I see these methods underlined by red, with message "The method ... is undefined for the type A". If I go into "open implementation" for the class A, Eclipse tries to open the source code attached to the old jar that lies in the maven repository. No source is attached, so I see only the tab with the name of the A class (it is there), but that is the old class version, without new methods.
Clean, Maven Clean - don't help. The same with restart Eclipse, clean all projects, reopening projects.
Please, don't propose to reinstall Eclipse - what I have is the picture JUST after reinstalling of everything, updating the project, maven installing it (worked), and adding these functions.
A Maven Install does not work for the same reason - falling on these references to new methods.
If I clean the repository by hand - on Maven Clean I am getting a FATAL error, with a demand for that old jar.
I have put the reference to the correct source of the A class to the Maven task source. I have added the reference to the correct project of the A class to the project of the B class in the Eclipse Properties of the project. Nothing changed.
There are similar problems here on SO, but I managed to get the some multiplication of all of them: both Eclipse and Maven had gone mad, no added references help, no cleaning helps.
Edit.
I have tried to make maven to create new snapshots, but the result is absolutely the same picture... "cannot find symbol" that is in the source! What is interesting, after removing of the repository the Eclipse starts to see the symbols OK. But I must run maven and it won't run with removed repository. Just as a crazy idea: Is there some maven tool to clean the repository so that it will know there is nothing there and won't try to look for things in it?
I have met with three unpleasant situations combined:
The local maven repository was damaged
The jar written in it was deprecated.
Due to some committing to local CVS branch and pulling and checkout from the common CVS repository it happened that parent snapshot referenced to by some poms and the main snapshot declared in the root pom had different versions.
Solution
The first problem can not be normally corrected using the plugin maven only. You have to install the standalone maven, add its bin to PATH, an launch in folder of your root pom (exit the Eclipse at first and stop jar that you are repairing, if you have it running):
mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false
Then, if you want to work in standalone maven, you should put the correct settings into youruserroot/.m2 folder.
After that,
mvn -U -X -e install
That will fail on every local pom with incorrect parent Snapshot. Go into every local lesser poms and correct the references. Repeat, until it stops to fail on snapshots.
I had found advice to run
mvn -U -X -e clean install -DskipTests=true
for installing all, but without test running. (I had repaired an error in the line, so don't try to google for it). But you can already use the plugin Maven at this stage, too.
So, you run Maven clean and Maven Install in the plugin... And hurra! - the classes see other classes as they are in the source code and not in some old jar, and that works in both maven and Eclipse.

Hinderance when attempting to add MySQL connector through Maven

When I use mvn clean install after adding the dependency in the 'pom.xml', I get the following output, instead of the expected Downloading: https://repo.maven.apache.org/maven2/mysql/mysql-connector-java/6.0.5/mysql-connector-java-6.0.5.pom-type of message.
You've only posted the end of the Maven output -- are you sure the new dependency wasn't downloaded before the tests were run? It finishes with BUILD SUCCESS... how do you know something's not working?
What changes did you make to the pom.xml file? If I could see those, I could offer some thoughts about whether they look correct or not.
In case there's any confusion on this point -- you indicate that you ran mvn clean install. These are lifecycle goals of the project itself. Some of what you posted makes me wonder if you really intended to run (thought you were running) the maven-install-plugin. That would look more like $mvn install:install ....

Categories

Resources