JUnit and other dependencies not recognized by CI build - java

Background:
So my team is using Microsoft's git services and we've set up some CI tests. We are not using Maven, and the project is connected to the remote server through the Eclipse Microsoft Team services plugin, but I try to interact with the remote repo mostly through the command line.
Current Strategy:
I'm not too familiar with how to deal with dependencies on a remote repo for Java projects but I've tried simply pushing the .jar dependencies in our build path with the rest of the source code (I know they're big and there's probably a better way to do this).
Problem:
When I push the .jar files, the CI tests still fail with the following errors:
src\JBLASTests.java(1):src\JBLASTests.java(1,): error : [javac] d:\a\1\s\
src\JBLASTests.java:1: error: package org.junit does not exist
src\JBLASTests.java(5):src\JBLASTests.java(5,): error : [javac] d:\a\1\s\
src\JBLASTests.java:5: error: package org.jblas does not exist
And then more error reports related to the missing symbols due to the packages not being found.
Questions:
1) What else needs to be on the repo to make the build work?
2) Is there a better way, besides Maven, to link the libraries to the repo?
(I'm not averse to using Maven I just want to find a simpler solution for the interim).
Apologies if this is a duplicate. I searched but couldn't find any other posts regarding this situation.

It looks like the dev who set up the CI tests set them up with an Ant build task despite that not being how we currently handle dependencies. Thank you howgler for pointing out that the CI might be building differently than I do locally. I'll post this answer in case anyone else runs into this issue and doesn't think to check the CI build settings (and also update the title appropriately).
Lesson
Make sure that the CI build task is the same as how you're building locally. Until you add dependencies and try to push them, your builds might be succeeding, so it can be misleading that your CI settings are incorrect.

Related

Maven install iff changes exist

I was wondering if there is a way to determine whether changes were made to the project and run mvn install only in that case. Similar to this question but I am not very interested in incremental build - Ideally I would like the build command to do nothing if no changes were made in the project. Is this possible
Thank you for your help.
You are looking into time independence of your build.
Currently maven is not built to support that (time stamps in jars etc) so I would suggest using a CI server for this listening to your git repository. For Maven projects Jenkins is a good start.

Test dependencies for white-box unit testing Java modules with Maven and Eclipse

I'm trying to convert existing Java projects with Maven and Eclipse into Java 9+ modules. The projects have unit tests and the unit tests have test dependencies. I need the test dependencies to be available in the test code, but I don't want them exposed to the rest of the world in the published modules.
I think Testing in the Modular World describes the Maven solutions well. In summary one solution is to create one module-info.java in the main source folder and another in the testing folder. The file in the main folder has the real dependencies. The file in the test folder adds the test dependencies.
The solution works well in Maven and I can build and run tests from the command line. However, when I import the project into Eclipse as a Maven project it balks. Eclipse complains that "build path contains duplicate entry module-info" and refuses to build the project at all.
Using the other suggested solution in the article with a module-info.test containing --add-reads has no effect and the build fails in both Maven and Eclipse as the tests can't find their dependencies.
To make matters more complex I need to import the test dependencies from Maven, but I also need to import standard Java modules that are not used by the main code. For example one unit test relies on the built-in web server provided by java.httpserver and as it is part of the JDK any magic done on the test dependencies will miss it.
Is there a solution for this that works in Maven and Eclipse (latest versions)? It sounds like a very common problem and the module system has been around for a while by now.
Note that I really don't want to change the project settings in Eclipse. I can fiddle with plugins in the pom files, but adding a manual routine where all developers need to edit the generated/imported project settings manually is not an option.
EDIT:
There is an open Eclipse bug report for this, see Eclipse bug 536847. It seems it is not supported yet, but perhaps someone can suggest a workaround?
The Eclipse emulation of the multiple-classpaths-per-project feature in Maven has been broken for very long. The symptom is that you can have non-test classes using test dependencies just fine.
Essentially Eclipse just considers each project to have a single classpath instead of two parallel ones which causes things like this to ... not do the right thing.
I would suggest splitting each of the problematic projects into two. One with the actual sources and one with the test sources (depending on the actual source). This will avoid the Eclipse bug and also allow you to use the newest version of Java for your tests while having your application built for an older version of Java.

Maven failing to build multi-module project only on a specific machine (works everywhere else)

I have a multi-module maven project that I inherited from another team and am now migrating to a cloud solution. We were able to get it working in a co-worker machine and pushed it to git. However, after I pull the exact same version of the code, it fails to compile on my machine with the obvious
cannot find symbol
The missing class is packaged in a dependency jar that is not declared in the pom, so it can only be a transitive dependency. However, I can't generate an effective pom to check this (because of the compilation issues, I suppose).
This is only failing for me, not my co-worker, so it really can't be a problem with the dependency declaration in the pom file. I'm running maven 3.5.0, from the main project folder, with exactly the same vm args and profile as my co-worker, except that it works for him and not for me.
The only difference between the two machines is I'm in mac and he's in good old Linux.
Does anyone has any idea what is messing my local build or what I should try to look for next?
I know it's a very vague question, but I'm completely at a loss. Fully available to send any more information required to help me out with this. Maybe I'm simply doing smt really stupid I can't put my finger on. Or maybe not. Any ideas?

How do I get IntelliJ to recognise resource bundle when compiling?

Ok, first up I am almost completely unfamiliar with Java and Java tooling.
I am attempting to contribute a bugfix to a Jenkins plugin. Code-wise the fix is simple, my problem is in trying to compile the project and run the tests locally.
I have installed IntelliJ IDEA 15CE and started a new project, pointing it to my local clone of the plugin repo.
It has gone away and 'downloaded the internet' in terms of Maven dependencies. Mostly everything looks ok. What I want to do is to run the tests...
If I right-click at the root of the project and select 'Run All Tests' I get the error:
Error:(115, 29) java: cannot find symbol
symbol: variable Messages
location: class hudson.plugins.copyartifact.BuildSelector
The source of this error is a line:
console.println(Messages.CopyArtifact_MissingSrcArtifacts(srcDir));
https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/java/hudson/plugins/copyartifact/BuildSelector.java#L115
As far as I can tell the Messages symbol should resolve to this properties file:
https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/resources/hudson/plugins/copyartifact/Messages.properties
...which IDEA recognises as a 'Resource Bundle' in the project tree view.
But it doesn't seem to recognise it when compiling the project.
I have no idea where to start fixing this. The tests run fine if I push a commit to a pull request on GitHub and let the cloudbees.com Jenkins server run them, but I'd like to be able to test stuff locally first.
Run the maven compile command from Intelli-J Maven tool. After compiling error will vanish.
When you compile it will generate a Messages.java file in generated sources automatically.

Why do my tests fail to run when migrating from maven2 to buildr?

I have a straightforward maven2 java project (JMS relaying system). After we released the first version, we found that we spent more time configuring maven than actually coding.
For the next release we wanted to clean up the build process and someone suggested migrating to builder. So I was tasked with doing just that.
I setup buildr (1.3.4) according to the documentation on their website. And then from the root of the project I typed the buildr command and then informed buildr to create the build file based upon my pom.xml. That processed fine and compiled all the code. All was gravy until buildr started running the tests. Here is the ouput:
Test framework error: taskdef class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found
Obviously the class specified isn't in my classpath. However, the buildr documentation says that all the required items needed for basic testing are included. Their documentation doesn't say that they need any specific libraries for ant or a version of ant. Although I do have ant 1.7.0 installed (not included in my classpath however).
Has anyone seen this before?
Update
I located the infamous ant-optional jar on the maven repository. Including that in my test.with options did not resolve the issue.
Running the buildr command with --trace gives this extra information...
Tests failed!
/pathtoruby/buildr-1.3.4/lib/buildr/core/test.rb:455:in `run_tests'
/pathtoruby/buildr-1.3.4/lib/buildr/core/test.rb:199:in `initialize'
Found the issue... Apparently there is an ant-junit.jar that is needed but for whatever reason in my local repository it was owned by root and not my local user account (OSX system). So it wasn't accessible to buildr. I deleted the items from my local repository and reran buildr (it downloaded the needed items).
Update
Also this caused a few other issues. It seems that a few other items in my local repository had strange permissions. I ended up just archiving my repository and letting maven reconstruct it. This resolved all my issues. I now have a nice build file that is 25 lines of code compared to my previous pom.xml file that was over 100 lines.
You get that error because JUnitTask isn't on the classpath. I'm not very familiar with Buildr so can't say if it is required for you to specify the JUnit jars or not, but if Buildr uses the system classpath, try adding JUnit to it and see what happens.
Once you've confirmed your builds will run with JUnit hacked in to the classpath, you can then try varying your configuration until it runs as you expected, or leave it as is.
Can you post the reference to the relevant part of the documentation? I didn't see anything (in my very brief reading of the site) that says required items are included.
Is it possible that you've not downloaded all the gems? If you run "gem update --system" to update Ruby, then "gem update buildr" you can ensure that the required dependencies have all been installed.

Categories