Running test without compile in SBT - how-to - testing

I'm new to SBT and I would like to know if it is possible to run tests without compiling. I mean to use a set of classes that have been already compiled.
Is this possible and what should I do to get this done?

sbt detects the available tests during compilation for efficiency. To run already compiled tests that are on the classpath and not in source files, it would be necessary to explicitly list them in the definedTests task. This isn't too straightforward, though.

Related

creating a Minecraft PVP client: error message when running minecraft [duplicate]

What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?
Additional information:
I have seen this after copying a set of updated JAR files from a build on top of the existing JARs and restarting the application. The JARs are built using a Maven build process.
I would expect to see LinkageErrors or ClassNotFound errors if interfaces changed. The above error hints at some lower level problem.
A clean rebuild and redeployment fixed the problem. Could this error indicate a corrupted JAR?
(rewritten 2015-07-28)
Summary: Eclipse had compiled some or all of the classes, and its compiler is more tolerant of errors.
Long explanation:
The default behavior of Eclipse when compiling code with errors in it, is to generate byte code throwing the exception you see, allowing the program to be run. This is possible as Eclipse uses its own built-in compiler, instead of javac from the JDK which Apache Maven uses, and which fails the compilation completely for errors. If you use Eclipse on a Maven project which you are also working with using the command line mvn command, this may happen.
The cure is to fix the errors and recompile, before running again.
The setting is marked with a red box in this screendump:
try to clean the eclipse project
you just try to clean maven by command
mvn clean
and after that following command
mvn eclipse:clean eclipse:eclipse
and rebuild your project....
Your compiled classes may need to be recompiled from the source with the new jars.
Try running "mvn clean" and then rebuild
The major part is correctly answered by Thorbjørn Ravn Andersen.
This answer tries to shed light on the remaining question: how could the class file with errors end up in the jar?
Each build (Maven & javac or Eclipse) signals in its specific way when it hits a compile error, and will refuse to create a Jar file from it (or at least prominently alert you). The most likely cause for silently getting class files with errors into a jar is by concurrent operation of Maven and Eclipse.
If you have Eclipse open while running a mvn build, you should disable Project > Build Automatically until mvn completes.
EDIT:
Let's try to split the riddle into three parts:
(1) What is the meaning of "java.lang.Error: Unresolved compilation
problem"
This has been explained by Thorbjørn Ravn Andersen. There is no doubt that Eclipse found an error at compile time.
(2) How can an eclipse-compiled class file end up in jar file created
by maven (assuming maven is not configured to used ecj for
compilation)?
This could happen either by invoking Maven with no or incomplete cleaning. Or, an automatic Eclipse build could react to changes in the filesystem (done by Maven) and re-compile a class, before Maven proceeds to collect class files into the jar (this is what I meant by "concurrent operation" in my original answer).
(3) How come there is a compile error, but mvn clean succeeds?
Again several possibilities: (a) compilers don't agree whether or not the source code is legal, or (b) Eclipse compiles with broken settings like incomplete classpath, wrong Java compliance etc. Either way a sequence of refresh and clean build in Eclipse should surface the problem.
I had this error when I used a launch configuration that had an invalid classpath. In my case, I had a project that initially used Maven and thus a launch configuration had a Maven classpath element in it. I had later changed the project to use Gradle and removed the Maven classpath from the project's classpath, but the launch configuration still used it. I got this error trying to run it. Cleaning and rebuilding the project did not resolve this error. Instead, edit the launch configuration, remove the project classpath element, then add the project back to the User Entries in the classpath.
I got this error multiple times and struggled to work out. Finally, I removed the run configuration and re-added the default entries. It worked beautifully.
Just try to include package name in eclipse in case if you forgot it
Import all packages before using it, EX: import java.util.Scanner before using Scanner class.
These improvements might work and it will not give Java: Unresolved compilation problem anymore.
Also make sure to check compiler compliance level and selected jdk version is same
As a weird case, I encountered such an exception where the exception message (unresolved compilation bla bla) was hardcoded inside of generated class' itself. Decompiling the class revealed this.
I had the same issue using the visual studio Code. The root cause was backup java file was left in the same directory.
Removed the backup java file
When the build failed, selected the Fix it, it cleaned up the cache and restarted the workSpace.

(Kotlin) Any workaround for annotation processing in Intellij IDEA

I've created a gradle modules main that contains main program logic and codegen that contains annotation definitions with processors. I found that:
Please note that kapt is still not supported for IntelliJ IDEA’s own build system. Launch the build from the “Maven Projects” toolbar whenever you want to re-run the annotation processing.
on kapt page (https://kotlinlang.org/docs/reference/kapt.html) but I really need it. May be there is some (may be ugly) workaround for that? Terminal background worker or prebuild tasks or something else?
P.S.
This can appear as duplicate question but I really didn't found working solution at the moment
At the current project we have this problem as well; we use gradle and the work around is to run gradle classes testClasses from the commandline - either in an external terminal program or in IJ's terminal (alt-F12 on macOS). This triggers kapt as well, and when this is done I do a Build/Rebuild project from IJ's menu as well.
This is enough if the code that is processed by kapt does not change too often (we just use mapstruct and querydsl).
If you are using maven a mvn compile test-compile should work as well.
Finally I found that repository that does work in Intellij IDEA without any workarounds (https://github.com/miquelbeltran/kotlin-code-gen-sample). Taken from https://medium.com/#Miqubel/hello-world-of-annotation-processing-in-kotlin-3ec0290c1fdd

How to avoid maven compiling testClass in normale compiling

I have a default maven project:
/src/main/java
/src/test/java (include *Test.java).
When I exeucte "mvn compile", maven also tries to compile the testClasses under /src/test/java. This fails, as of some dependencies such as JUnit are under "test"-scope. Changing the scope of e.g. JUnit to "provided" everything works fine.
How can I avoid maven to compile testClasses when compiling? In my understanding, I expect to maven to compile this files only when executing "testcompile".
I am using maven 2.2.1
I believe it is nothing to do with the scope of JUnit. Normally we set JUnit's scope to test (instead of provided) and everything is just fine.
src/test/java is compiled by Maven Compiler Plugin's testCompile goal. However, you don't need to explicitly run that goal. Please have a look in topics about Maven's Lifecycle. For example, if you run maven install, it is implicitly going through many phases (e.g. compile, compile test, generate resources etc), and many of them is bounded to a default plugin goal.
If you want to avoid test source from building, from Maven Compiler Plugin's usage page, compiler:testCompile will be skipped if you turn off testing by setting maven.test.skip=true
So, if your unit tests are not yet ready, just build with Maven, with -Dmaven.test.skip=true parameter.
Just to add, this is absolutely not a good practice to assume "unit test failing" being normal during development.
Just use the skip parameter for the maven-surefire-plugin which skip tests as well as compiling the test.
The pom.xml had defined "sourceDirectory" incorrectly. Removing it fixed the issue
Instead of command "maven clean compile" , use "mvn -B -Dmaven.test.skip=true clean compile". This parameter skips test.

How to add the target jar as a test resource of the same project?

I'm developing a Solr plugin and using the Solr test-framework I place a test SOLR_HOME dir under test/resources with /conf/ and /lib . Now the framework inistantiates a SolrCore and loads my plugin from /lib. Not an issue to output the jar of the plugin to /lib, but the issue is that the plugin is not yet available since it still needs to past the test (chicken and the egg).
How do you recommend solving this? I see those options:
Create another project for the tests with a dependency on the plugin, and in it run the tests. Simple enough, but how do I ensure that everytime the plugin is built also the tests of this other project is built? The point of the automated tests at every build is to having a new plugin jar which breaks the tests.
In dp4j pom.xml I build the project on 2 phases, in the 1st I <include> only the annotation processors while in the other I compile the tests which rely on the annotation processors compiled in the eariler phase.
I'm in favor of 2 since copy-pasting the configuration doesn't seem a bad option, and makes it seem less complicated than it probably is. I don't remember if I had asked about it here - what do you recommend? Any other case studies /working code to look at?
there's a 3rd. most probably best solution ~ do nothing!
I was under the impression that the Solr Testframework need to load my plugin from /lib but apparently it doesn't need to, it can load it from test-classes, all on its own!

Looking for a simple example to fire "make" from Maven2

This is a transitional solution.
I don't want to write my own plugin.
I have too many small, scattered makefiles to convert to pom.xml all at once.
I'm trying to move to Maven2 as a skunkworks project and gradually migrage new + changing code to pom.xml files.
The arch-independent C/C++ solutions are not needed - plus the Makefile run multiple scripts to generate code before compilation.
Any pointers to extending "mvn deploy" to handle "make deploy" would be great.
Thanks
AJ
You should check Codehaus' related CBUILDS project. It may help you with downloading dependencies, unpacking, patching, and invoking make.
I'm a bit confused as to why you're moving towards maven with C projects, but if I were you, I'd look at gmaven-plugin to execute an inline groovy script to invoke what you need. Then, if you want to create a plugin later, it should be easy to migrate to one.