Invalid error messages in Spring Tool Suite - spring-tool-suite

I am running into a problem when trying to duplicate a project in STS.
I am getting lots of error-messages of type
"Import XY cannot be resolved..."
in my code which runs and builds completely fine with maven and which is a more or less exact copy of the original project (with different artifact ID a.s.o. in the corresponding pom) which is shown as error-free.
What I did until now:
I wasn't sure how STS-duplicate works and thought that some configuration may have been duplicated but would have needed some changes, so I created a new project and inserted the code manually in manually new created classes and added the needed dependencies to the pom.
Again this compiles and runs perfectly while still showing the import errors.
Did anyone run into similar problems and has a solution to this?
(I had something similarly strange in the past where STS showed an error on project-level but no file in the project would have an error-indicator.)

Run a Maven -> Update Project..., that should help... :-)

Related

Cannot build/run Scala project in IntelliJ after packaging with Maven

So my Scala project was working perfectly fine in IntelliJ, then I tried to run package in Maven to obtain a .jar file, which was not working because I was missing a dependency. So I tried to edit pom.xml however reverted it back shortly.
Anyhow, thereafter, without any changes I tried to run my Scala project normally locally and it doesn't work anymore. I get the error:
Error: Can not find or load main class Name.Name
I double checked Edit Configurations in IntelliJ and the main class is specified.
What went wrong? There has been no changes at all except that I tried to package my project using Maven, and then my normal program stopped working.
Solved it by recreating the project from scratch, however I'm still unsure what the cause was.

Intellij Idea is loading *.class file instead of *.scala from library source

My problem is best described with a screenshot:
As you can see, there is a org.virtuslab:unicorn-core_2.11 dependency loaded in my SBT/Scala project. The jar file with corresponding sources is available as well. For some reason, Intellij Idea decided to ignore the available source file Table.scala and uses the .class file instead. Clearly, all other files are okay.
Obviously, without the information contained in the .scala file, Intellij is not able to properly analyze my code and I'm getting Cannot resolve symbol BaseIdRepository errors (and similar) all over my project.
I manually checked the source package and the Table.scala file is there and seems alright. Plus this worked flawlessly until two days ago. I don't know why it broke down. I tried to revert my project using git to an earlier version when this was still working, but no luck.
I tried to both downgrade and upgrade the library, I tried to remove it and add it again, I tried create a completely new project based on existing sources, but once again, no luck.
Just for the record, I'm able to compile and run my project. The only thing that might be related is this warning that I get when compiling the project:
[warn] /home/tobik/scala/payola-viz/src/app/model/appgen/repository/UsersRepository.scala:7: Could not find any member to link for "BaseIdRepository".
I got an update for the Scala plugin which seems to fix this issue.
In case you experience similar problems, this temporary solution worked for me: I added the unicorn sources directly to my code base and manually removed it from the project libraries. I got rid of the errors and it still compiles as the library remains as a dependency inside built.sbt. To avoid polluting my project, I added the included sources to .gitignore. The workaround broke after a while but all I had to do was repeat the procedure again.

Unit test class runs old version in eclipse

I have a JUnit test class in my project which is updated incrementally - I add tests every few weeks and sometimes modify the tests' code.
Surprisingly, when I run the test class using eclipse JUnit Runner 4, it runs my old code (before the update) and not the new one. I can change the code, add or remove tests but it still runs the old code.
I tried to isolate the problem and run a single test that I've just written and got the infamous "Unrooted tests" error without any stack trace to give me a clue what the problem is.
I did some research and according to a few other threads here, many people encountered this problem with regards to JUnit 3 \ JUnit 4 compatibility, but this is not the case here - I annotate all my tests with #Test and I do NOT extends the TestCase class.
Cleaning / Building all eclipse projects doesn't help.
However, this problem does work itself around when I mvn clean install my project, but this takes too much time.
Also, renaming the class (Alt+Shift+R in eclipse) gets the new code to run immediately, but renaming it back to its original (and valid) name, gets the old code to run again (WTF?)
Help would be appreciated,
10x
I managed to solve the problem on my own (inspired by a comment contributed by Harlard).
After examining the target directory of my project, I noticed that the test-classes dir inside it doesn't include the binaries of my test.
I then noticed that I misplaced the classes within src/test/java and put them in a package structure that doesn't conform to the package structure of my project, they were direct sub-directories of src/test/java.
Therefore, eclipse didn't put them in the correct place and the only way to generate binaries for them was by executing a maven build.
After refactoring all my test classes to the correct package structure, everything worked perfectly.
I had the same issue. It was due to a defective .classpath. Removing this .classpath and re-importing the project, generates a correct .classpath and fixed the environment.
Another solution would be manually deleting the "target" folder of the project and rebuilding it. This should solve all problems of this kind.

ScalaTest Run Configuration in Eclipse: cannot find Suite Class

Problem: I cannot setup Run Configurations to run scalatest for the Scalatests in my project.
Steps to reproduce:
Right click on Scala Suite and click on Run as -> Run configurations..
On the left, I see a configuration template for ScalaTest. I click on New and fill the Name but it cannot find the suite-class.
Note: It is mentioned here that I should see Run as -> ScalaTest - Suite but I do not see that option. I tried using context menu in the editor, and in the package explorer
Steps taken:
Using: Scala IDE for Eclipse version: 2.1.0.m3-2_09
Using SBT, assemble project, run eclipse command and then import project and dependencies into Eclipse
Project compiles. ScalaTest code compiles(scalatest_2.9.2-1.8.jar is in the 'Referenced Libraries' configuration)
I've been fighting a similar problem for the past few days; Lily / Jimbo's answer didn't quite match my situation, but helped me find the right direction.
In my case, I was using a third-party library that I'd copied in. The package names of the classes and tests matched, but the folder structure did not -- all of my tests were directly in Play's "/test" folder, rather than in folders that matched the package names. This didn't show any errors, but was broken: packages ought to match folders. When I built the right folder structure underneath test, and recompiled, the expected "Run As -> ScalaTest - Suite" options showed up.
Don't know if your problem is the same, but you might check this if you haven't already found the issue...
This could be caused by a misalignment between the scalatest and the scala eclipse IDE version. Try scalatest_2.9.0-2.0.M5b.jar or scalatest_2.10-2.0.M5b.jar. The former jar definitely works with ide 2.0.9.x so maybe the new version needs the 2.10 jar. Pick your version carefully from here
Willem's answer is what worked for me. Getting both plugins from the same update site (from the list on Scalatest's github site), seemed to work for me using Kepler.
for my case, one click on 'Reimport All Maven Projects' icon, like 'Refresh' icon, solved the problem.
Not sure if you fixed the error, but I had similar a error yesterday and was pulling my hair trying to fix it (none of the suggestions I found by googling seemed to help me). So for me, it turns out that it's as easy as package hierarchy in my test suite.
I am using the play framework, so naturally my folders look like this controllers.package1.package2.... and this applies to my test folders also.
Now my test classes however, have the package definition package1.package2..... (no "controllers" as prefix).
If I run the tests on sbt/play command prompt, it's not a problem. But running them through Eclipse would give me the problem you described.
So anyways... thought I'd share this, in case this could help.
it's a bit annoying combined with the view template compile issue in play framework. but my approach is to regenerate the eclipse project file and add view template path into the class path

Groovy Eclipse can't launch junit tests

In Eclipse with groovy plugin, I try to launch a test #Test public void testToLaunch() {...} but I have the error:
The input type of the launch configuration does not exist
What input type is in the context of launch configuration? (can't find such an entry in launch configuration window)
Note: I try sts 2.8.1 and e3.7
This happens normally when the folder in which test case is present is not a source folder, please check this post as well.
Hope that helps!
This can also happen if there is a problem with the groovy class. A few things to check:
1) Ensure that the class name exactly matches the filename (filename = MyTest.groovy)
package com.mypackage;
import groovy.util.GroovyTestCase;
class MyTest extends GroovyTestCase {}
2) Ensure that the package defined in the file matches the package the file is actually in.
In Eclipse you can do
Right click -> properties -> Java build path
Notice test folder is not available in sources. Add it.
Add folder -> Select test -> OK
Now rerun you unit test cases.
This happened to me, and I just restarted Eclipse (GGTS) and everything was fine again.
I had a spelling mistake which lead to that error message. My test class file name was named JUnit5Test.java (with upper U) and the class itself was named Junit5Test (with lower u).
I was using Spring Tool Suite 4 (4.8.0.RELEASE).
This also happened to me. But these tests are written in Groovy. The problem I encountered has to do with how the IDE (Eclipse Kepler, Java EE) first opens a Groovy project after executing "mvn eclipse:eclipse".
The Build Paths do not reference the Groovy source files correctly.
To resolve, I:
Right-click on the project, select "Build Path" > "Configure Build Path..."
Select "Source" tab
For test and src folders (.../src/main/groovy, and .../src/test/groovy)
make sure "**/*.groovy" is set as "Inclusion patterns", not "**/*.java"
Hope this saves time for someone.
Cheers!
I had the same error message when I head the test-class duplicated both in the main Java source folder and the testsrc folder. Removing the incorrectly placed one in the main Java source folder solved the problem for me.
2019 Update: This drove me crazy for days even with latest Eclipse and fresh installs (Mac, Grails 4, Gradle 5.1.1, Java 8). Some above examples led me to the solution.
My problem was more that the code I was testing included a mix of groovy and java src/main code. It gave me NoClassDefFound on the .groovy classes when I ran my Spec as JUnit.
Solution: I had to modify my Run/Debug Configuration to include build/classes/groovy/main. Then it worked. It's a little bit of a pain to remember to that for every new Configuration, but, it keeps me going. I hope it helps you.
Whenever you create a Junit test in eclipse, make sure your Junit test file is inside src/test/java folder.
I had a similar problem. Like others have already pointed out, it was about source folders. I had to change my source folder setup. There was an empty src-folder that disappeared after I right-clicked on it and selected 'remove from build path' from Build path menu. After that I right-clicked both java/src and java/test folders and chose Build path > Use as a source folder. And suddenly my tests were JUnited!
In similar situations I'd advice to remove all source folders from build path and add them again when you're sure you've got the right ones. Your source folders should be those with Java package structure under them. In case of proj/java/test/com/stackoverflow/main it's the 'test' folder.
This is what resolved for me (Eclipse Oxygen). I had already done what Robert suggested in the earlier post. I was still getting the error. When I went to edit the configuration for junit launch, I saw that the Test Class field just had the class name. I had to hit the Search button to the right. The Test Class field now had the complete name for the class
com.mycompany.mypackage.MyClass
With this I am able to run the JUnit. But I have to keep fixing this for every run.
Found another way to cause this message. The cause turned out to be an empty copy of MyTest.java under src/main/java, as well as the real one under src/test/java.
Think the empty file was a hangover from some refactoring and was oddly causing no compile errors either. Deleting it enabled the test to run again.