Eclipse detects cycle in build path, maven does not - eclipse

Eclipse gives me the following errors when building:
A cycle was detected in the build path of project 'com.X'. The cycle consists of projects {com.Y, com.Y}
A cycle was detected in the build path of project 'com.Y'. The cycle consists of projects {com.X, com.Y}
However, maven builds totally fine from the command line with "mvn clean install" and manual inspection of the POMs indicated that com.X depends on com.Y but com.Y does not depend on com.X.
Any idea what might cause this?

eclipse and maven are using different build configuration files, one (eclipse) contains circular dependency, another (maven) does not.

Related

Gradle Eclipse Plugin only half-working

I am trying to achieve the following between Eclipse and Gradle:
Allow Gradle to handle 100% of my local build logic; only use Eclipse as an IDE for syntax highlighting, refactoring, etc. Every time I wish to build my app I want to drop into a command line and run a Gradle build invocation from there.
I want the dependencies closure of my build.gradle file to be the sole location for configuring 3rd party dependencies; every time I make a change to this closure (adding/removing a dependency/JAR), I want Eclipse to automagically "see" this change and adjust my project's classpath accordingly
I installed the Gradle-Eclipse Integration plugin and then I followed this tutorial for configuring it correctly.
First I ran:
gradle clean build
And then I added:
apply plugin: 'eclipse'
To my build.gradle, and then ran:
gradle eclipse
I saw a lot of output, the tail end of which is:
gradle eclipse
:myapp:eclipseClasspath
Download http://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2-sources.jar
Download http://repo1.maven.org/maven2/org/sonatype/sisu/inject/cglib/2.2.1-v20090111/cglib-2.2.1-v20090111-sources.jar
Download http://repo1.maven.org/maven2/asm/asm/3.1/asm-3.1-sources.jar
Download http://repo1.maven.org/maven2/com/google/inject/guice/3.0/guice-3.0-sources.jar
Download http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.3.7/groovy-all-2.3.7-sources.jar
Download http://repo1.maven.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar
Download http://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1-sources.jar
:myapp:eclipseJdt
:myapp:eclipseProject
:myapp:eclipse
I then opened my .classpath file and see that its been correctly updated with all the transitive dependencies defined in my dependencies closure back inside build.gradle.
However, there is not visual indication inside Eclipse that anything is wired correctly. With Ivy or Maven, you usally get something like a Ivy Repository Manager or Maven Dependency Library that automatically changes anytime you modify ivy.xml or pom.xml.
Most importantly, this just doesn't seem to be working! As you see above, Apache Commons Lang 3 is a dependency, but when I try to add org.apache.commons.lang3.exception.ExceptionUtils to a Groovy source file, Eclipse can't find it. I have already tried restarting Eclipse to see if that shook any bugs out.
Am I just not using this plugin correctly, or does it just not work? Using Groovy/Grails Tool Suite 3.6.0.RELEASE here, which is based on Eclipse Luna 4.4.

Eclipse with m2e not building tests

I have an Eclipse project that uses Maven. The regular source files (ie, in src/main) build fine in both Eclipse and Maven. However, the test files (ie, in src/test) will only build in Maven. I cannot find any way to get them to build in Eclipse.
That is, the tests in Eclipse are run as the last version which Maven compiled. Before I used Maven, tests would be compiled automatically when they were run in Eclipse. "Build automatically" in the project menu is still enabled.
This only affects the tests (which are JUnit 4 tests). As mentioned, the regular source files are being built automatically correctly.
Here's the POM file, with irrelevant data pruned: https://gist.github.com/anonymous/10001049
Add the src/test directory to your build path. Windows / Preferences / Java / Build Path, or something like that.
Updating the project might also work, since m2e can get out of sync with your pom file quite often.

Gradle eclipse classpath - Switching between SNAPSHOT and project dependency

We have a multiple modules in our Java project and each module publishes SNAPSHOT jar files to Nexus repository. All the sub-modules are directly dependent on the SNAPSHOT jar files.
During development, we want to depend on the Eclipse project rather than SNAPSHOT jars. So we introduced a flag which switches between the dependencies as shown below.
if(System.properties.'setupProject'){
compile project(':Core')
compile project(':Module1')
compile project(':Module2')
}else{
compile 'com.test:core:0.1-SNAPSHOT'
compile 'com.test:module1:0.1-SNAPSHOT'
compile 'com.test:module2:0.1-SNAPSHOT'
}
Executing the following command generates the .classpath file as expected.
gradle eclipse -DsetupProject=true
Is there a better way to do this? Can we use Gradle configurations to achieve the same?
I could not find good examples for the same.
At the moment this is the way to go. You might tweak this even more and instead of using a System property to mark a project as available you can check if the project folder is available (project is checked out)
cheers,
René

Maven build is successful, Eclipse detects cycle in dependencies

I'm working on a large project that consists of many smaller projects (about 140) that are all managed by maven. There is a master pom and a pom for each individual project.
Now I have introduced 2 new small projects, A and B, with the dependency A -> B. Furthermore B depends on another existing project C, so B -> C. A is used by another project D which is (as far as I've seen) independent from C. I'm not sure because the structure is very complex and I don't want to sit there sifting through poms all day.
This means I have a dependency graph like this: D -> A -> B -> C
When I build the master pom in maven (clean install) it finishes successfully. So does the eclipse:eclipse goal that generates the Eclipse project files. When I refresh the projects in Eclipse it rebuilds everything and finishes with the error "A cycle was detected in the build path of project...". This error occurs in about 30 of the 140 projects. Ofcourse Eclipse doesn't tell me what the cycle looks like...
How can it be that maven does not detect a cycle in the dependencies but eclipse does? I thought that the Maven Eclipse plugin just mapped the dependencies from the pom to the Eclipse .project and .classpath files?
The fact that Maven doesn't complain about cycles tells me that there is no dependency C -> D.
I had the same symptoms but with no actual maven cycle. I dealt with this in eclipse Indigo in a workaround fashion: I closed and deleted the eclipse projects that reported this error (not deleting the files making up the project), then re-created the maven projects in eclipse by importing the source files into my workspace with "File->Import...->Maven->Existing Maven Projects". That took care of it.
You may have dependencies with the scope test or runtime. Maven only looks for cycles in the compile phase. Eclipse or m2e doesn't differ the dependencies in scopes.
You probably have previous Eclipse settings on your projects, try this steps:
Remove all projects from Eclipse.
Run 'mvn clean eclipse:clean;' from the console or delete all hidden files from all project folders: .project, .classpath, .wtpmodules, org.eclipse.core.resources.prefs, ...
Reimport the projects into Eclipse
This may fix the problem!

m2eclipse : Maven dependencies as JAR's not projects

I'm having maven project on Eclipse with m2eclipse plugin. This project has some dependencies. Some of them are libraries as slf4j, apache-commons etc. But there are also mine libraries, that I'm developing simultaneously in eclipse. Unfortunately m2eclipse creates build path in such a way that my libraries are added to the classpath not as a JAR archives from M2 repository but as class files from /target/classes directory. For that reason I can not use maven-shade-plugin beacuse I'm gettin a message:
" Error creating shaded jar: error in opening zip file /home/user/workspace/my-project/project-a/target/classes".
When I'm building project-a from command line using mvn clean install everything works well - shaded JAR is generated. How to fix it?
After few hours of searching I've already found solution. This can be made by configurinng Maven Build Configuration
1. Select arrow on Run as.. button
2. Select Run configurations...
3. Select yours project Maven Builder
4. On the right tab (Main tab) deselect: Resolve Workspace artifacts.
Click Apply and build your project - all will work as you wish :).