Hi Ladies and Gentlemen,
We've quite big project with own build framework, based mostly on Java (however other languages exist).
We'd like to use Sonar Hudson plugin to graphically present various code metrics.
How do we do this?
Do we need to change project structure and bring it to maven or there is a workaround to just specify where to get test results and other artifacts from?
Thank you
The method we are using is this:
we built a custom pom.xml build file specific for sonar (we are using ant for other build purposes)
it only has to perform test well, so specified hardcoded dependency references with
<scope>system</scope>
we didn't change the project structure for maven, you can specify in maven custom scr, test, resources directories (as long as you have only one src and test directory)
the command used in CI is
mvn clean compile sonar:sonar
We are using Continuum for the CI part, but it should work just as well in Hudson.
This method did not change any other build items, it's just custom made for Sonar. But it does open the way for a Continuous Integration (daily) build, or for using maven as a build tool. This method is similar to the "sonar light mode" described here
More information here:
http://docs.sonarqube.org/display/SONAR/Documentation
http://docs.codehaus.org/display/SONAR/Continuous+Integration
You can use sonar without Maven. you just have to tell it where the rport files are with properties: sonar.cobertura.reportPath, sonar.clover.reportPath, sonar.surefire.reportsPath…
See here: http://sonar.codehaus.org/tag/ant/
There's a tick box to set these values when configuring the build in hudson - it is called "Check if this project is NOT built with maven2"
Related
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.
I'm trying to run a complete Maven build of multiple projects for an automated build tool. If unit tests fail, but the project itself builds correctly, I want to be able to continue the build and detect this after the build completes. I tried doing this:
mvn clean package -Dmaven.test.failure.ignore=true -Dmaven.test.error.ignore=true -Dmaven.test.reportsDirectory=/Users/bfraser/misc/reports
The "maven.test.failure.ignore" and "maven.test.error.ignore" properties work fine. However, surefire seems to ignore the "maven.test.reportsDirectory" completely (in fact, if you look at the documentation for the test goal, the reportsDirectory property is not documented to be tied to the system variable). This may be because I'm building a multi-module project? All reports seem to go in the target/ folder of the subprojects.
It is very difficult for me to be able to edit the POMs in an automated way since many of them have parent POMs that might be on a Nexus repo somewhere, etc. -- I need to be able to do this externally to the project (preferable via command line switches, but if I need to create some files so be it... as long as I don't have to edit the project POM it's all good).
I just need to know if any test failed. I'm not particularly fussy about what/how many tests failed.
If I have a repository setup for unit testing with travis-ci from what I can tell I have to include the JUnit .jar files within the repo so that travis-ci can find them.
Is there a way to avoid storing the .jar files for JUnit itself?
EDIT This is the repository: https://github.com/krisives/jbloomer
Travis CI have a page on Building a Java project. That page lists three ways they support building Java projects: Maven, Gradle and Ant. Maven and Gradle have support for dependency management, but Ant does not. Your project should switch to Maven/Gradle, introduce a dependency manager (such as Ivy), or hand-roll a half-baked, custom solution (i.e. you can call whatever Ant target you want). Maven, Gradle or Ivy would be preferred solutions (IMO).
I am new to using github and have been trying to figure out this question by looking at other people's repositories, but I cannot figure it out. When people fork/clone repositories in github to their local computers to develop on the project, is it expected that the cloned project is complete (ie. it has all of the files that it needs to run properly). For example, if I were to use a third-party library in the form of a .jar file, should I include that .jar file in the repository so that my code is ready to run when someone clones it, or is it better to just make a note that you are using such-and-such third-party libraries and the user will need to download those libraries elsewhere before they begin work. I am just trying to figure at the best practices for my code commits.
Thanks!
Basically it is as Chris said.
You should use a build system that has a package manager. This way you specify which dependencies you need and it downloads them automatically. Personally I have worked with maven and ant. So, here is my experience:
Apache Maven:
First word about maven, it is not a package manager. It is a build system. It just includes a package manager, because for java folks downloading the dependencies is part of the build process.
Maven comes with a nice set of defaults. This means you just use the archtype plugin to create a project ("mvn archetype:create" on the cli). Think of an archetype as a template for your project. You can choose what ever archetype suits your needs best. In case you use some framework, there is probably an archetype for it. Otherwise the simple-project archetype will be your choice. Afterwards your code goes to src/main/java, your test cases go to src/test/java and "mvn install" will build everything. Dependencies can be added to the pom in maven's dependency format. http://search.maven.org/ is the place to look for dependencies. If you find it there, you can simply copy the xml snippet to your pom.xml (which has been created by maven's archetype system for you).
In my experience, maven is the fastest way to get a project with dependencies and test execution set up. Also I never experienced that a maven build which worked on my machine failed somewhere else (except for computers which had year-old java versions). The charm is that maven's default lifecycle (or build cycle) covers all your needs. Also there are a lot of plugins for almost everything. However, you have a big problem if you want to do something that is not covered by maven's lifecycle. However, I only ever encountered that in mixed-language projects. As soon as you need anything but java, you're screwed.
Apache Ivy:
I've only ever used it together with Apache Ant. However, Ivy is a package manager, ant provides a build system. Ivy is integrated into ant as a plugin. While maven usually works out of the box, Ant requires you to write your build file manually. This allows for greater flexibility than maven, but comes with the prize of yet another file to write and maintain. Basically Ant files are as complicated as any source code, which means you should comment and document them. Otherwise you will not be able to maintain your build process later on.
Ivy itself is as easy as maven's dependency system. You have an xml file which defines your dependencies. As for maven, you can find the appropriate xml snippets on maven central http://search.maven.org/.
As a summary, I recommend Maven in case you have a simple Java Project. Ant is for cases where you need to do something special in your build.
I want to use same configuration for FindBugs irrespective of whether it is executed form eclipse or ant build.
Using ant FindBugs task, it is possible to specify which classes FindBugs should analyze. However, FindBugs eclipse plugin has no such option. It considers all classes in the buildpath.
E.g. In case of maven based project the eclipse build path contains both application classes and test classes. I want FindBugs eclipse plugin to not analyze test classes. Is it possible?
Is there a way to customize FindBugs eclipse plugin to indicate classes to analyze?
Thanks in advance.
It doesn't seem possible, but you could create a second project referencing the same source files (sources only, not tests).
Findbugs would only be active with that second project, for you to inspect the result of a static code analysis.
You can specify exclusion filter for Java project via preferences -> filter. The filter file is written in xml. See "Filters" chapter in FB manual: http://findbugs.sourceforge.net/manual/filter.html.
Since 2.0.3 one also can re-use Eclipse configuration with ant builds, see the help for "userPreferencesFile" ant option: http://findbugs.sourceforge.net/manual/anttask.html#d0e1339