Is any method to using "Workspace project" maven repository? - eclipse

We have: Eclipse 3.6, Maven (M2Eclipse), Two Project (ProjectA and ProjectB) with pom.xml.
ProjectB depends of ProjectA (using maven).
If we install ProjectA to local repository (maven install), ProjectB resolve dependencies OK.
If we not install ProjectA to local repository. In Maven POM Editor we add ProjectA as dependency of ProjectB (M2Eclipse using "workspace project" repository to resolve this dependency).
OK, added. But if we do "maven package" or others plugins goals... dependency not resolved.
And we have somethings like that:
Downloading: http://repo1.maven.org/maven2/Artifact/ProjectA/maven-metadata.xml
and of course it cannot be resolved.
Now is the Question. How I can use "Workspace project" when build ProjectB?
P.S. Why I'm not using "maven install"? OK, it is 100% method, but when I do many small changes in several it is too long do excess operations.
P.S.S. "Workspace project" we can see Window -> Show View -> Maven Repositories.

I think the idea of running the 'Maven package' or similar goals from Eclipse is to do whatever maven would have done if run from the commandline for example. The scenario that you are giving wouldn't have worked on the commandline either.
If project B depends on project A (via pom.xml) that means that project A should be available in a repository. Whether that's local (via mvn install) or remote via (mvn deploy) doesn't matter, but mvn package isn't enough. That will just put a package in the /target folder.
The only exception would be if both projects reside in the same reactor I suppose, that is both projects are modules of some other 'parent' project. In that case triggering maven targets on one of the submodules might be able to resolve the dependencies okay. Not 100% sure though.
Back to your question: "Now is the Question. How I can use "Workspace project" when build ProjectB?". No, I don't think so.

Workspace dependency should be resolved. Try this,
run > run configurations > Maven Build > new > Select Project B > check "resolve Workspace Artifact" > set goals as package
select offline check-box as well.
Perhaps, you need to provide exact version of projectA in projectB dependency tag. Else, it may look to Maven public repository to pull the latest.
Hope this helps.

Try this (in ProjectB):
Maven > Enable Workspace Resolution
A similar issue was solved here in that way.

Related

Do dependencies need to be added through both the Eclipse GUI and the Gradle configuration files?

Two Gradle Git projects need to be created, within the same repository, using the Eclipse IDE. Project A depends upon a third-party library (a JAR, source code, Javadoc and natives) and project B depends upon project A.
Without Gradle, both projects would be created and Git would be enabled with Project Explorer > [Project Name] > Team > Share Project. Then, dependencies would be added via Project Explorer > [Project Name] > Build Path > Configure Build Path, followed by Projects > Add and Libraries > Add External JARs (which would also allow the specification of the locations of related source code, Javadoc and natives). This would enable automatic code completion of Project A from Project B as well as source code and Javadoc integration, within Eclipse.
With Gradle, should the settings.gradle or build.gradle files be manually edited, without adding dependencies through the Eclipse GUI, or must both be used simultaneously? Additionally,how does this effect which hidden files should be indexed by Git (.project, .classpath, .settings, .gradle)?
How is this setup through Eclipse and Gradle?
When you use a build-tool like Gradle (or maven), it is kind of assumed that the build-tool is in charge of configuring stuff like project dependencies and classpaths.
This kind of conflicts with the Eclipse UI which is kind of built to allow you to manage classpath / dependencies via its own ui.
But the Eclipse UI only controls what eclipse uses as the classpath when the Eclipse JDT compiler compiles your code... inside Eclipse.
So if you change things that way, then Gradle will not know about these dependencies and the build won't work.
Yep, this is definitely confusing :-)
The proper thing to do is manage your dependencies and project configuration entirely through gradle. So that means editing the build.gradle and settings.gradle.
The tools (BuildShip or STS Gradle Tools) provide a 'bridge' to try and configure Eclipse projects in conformance with your build.
E.g they may offer a 'Update Project' or 'Refresh Dependencies' command in project context menu.
Even if you don't use Gradle tooling, this kind of holds true. You then would use Gradle's 'ecplise' plugin and run a command like
gradle cleanEclipse eclipse
To generate the eclipse project config from the build config. Then import the project into Eclipse as configured by gradle. Also in this case, it would be a bad idea to use Eclipse UI to make changes to the buildpath since ultimately it has the same issue, changes you make to those generated files may make things compile inside Eclipse, but Gradle doesn't know you changed anything. And the next time you run gradle cleanEclipse eclipse your changes are also blown away.
As to your specific questions:
should the settings.gradle or build.gradle files be manually edited ...
Yes.
... without adding dependencies through the Eclipse GUI ...
Yes.
... or must both be used simultaneously?
No, only configure things in gradle. Then 'synch it up' to eclipse with some tool (BuildShip / STS Gradle / gradle cleanEclipse eclipse)
How does this effect which hidden files should be indexed by Git (.project, .classpath, .settings, .gradle)?
General rule of thumb. Only index the stuff that defines gradle's behaviour (there may be some exceptions, but in general try to minimize them only violate this rule if you have a good reason).
So specifically don't put in git these 'eclipse metadata'
.settings
.project
.classpath
Do put in git: the gradle wrapper and its properties file.
Gradle also has a .gradle folder. It belongs to gradle, not eclipse, buts is caches and things which are 'transient'. You don't want those in git either.

Tell eclipse to use Source and not Jar

I have a maven project that depends on a jar (say A). When running the project, it uses the jar under Maven dependencies.
I have the source of A with me and its opened as a project in Eclipse. When I run the project I need to use the source and not the jar. How do I tell Eclipse to use the source and not the jar?
m2eclipse does this by default, if that is a full Maven project. See the context menu in the screen shot of http://www.sonatype.com/books/m2eclipse-book/reference/eclipse.html#eclipse-sect-resolving-dependencies, where it says "Disable workspace resolution".
If you don't find that context menu entry for your project, then you probably have a Java project with a POM file, which is not marked as Maven project type in Eclipse. Use the context menu Configure->Convert to Maven project in that case.
I had problems with the workspace resolution of m2eclipse as well. It would recognize the dependency (A) and show a different icon in the dependency view (which indicates that the dependency is resolved from the workspace) but the classes were not found.
Only when I ran a mvn install on project A all artifacts were generated and the resolution started to work. Maybe that helps.
Also I found a couple of hints (related to not working workspace resulotion) that suggested to (re-)import the project again using "Existing Maven Projects" wizard.

Maven dependency issue in eclipse

I have multiple related projects open in a workspace in eclipse. One of the projects has a maven dependency on the output jar from another project. In this project, any references to the classes in the dependency always show up as red (unidentified) and I get no code completion or javadoc showing up for them. If I manually add the jar to the classpath, then I no longer have this problem. The thing is, I don't want to have to manually add the jar every time our revision changes, that's what Maven is for. Any ideas on how I can resolve this? it seems like a bug to me, but I'm not sure...
The correct way to do this is the following:
Make sure that m2e or m2eclipse (depending on your version of Eclipse) is installed: http://www.eclipse.org/m2e/
Use the dependencies section in the POM file exclusively, don't fiddle with the Eclipse project references. Right-click the project, then select Maven > Update Project Configuration to reset the project to the Maven default settings. This way, m2e has ownership of the dependencies.
If you don't have that option, you might need to enable the project for Maven usage. Right-click the project, then Maven > Enable Workspace Resolution or Maven > Enable Dependency Management.
Make sure all referenced projects are open in Eclipse and have the Maven nature enabled.
Check the Maven settings for each project, make sure that groupId, artifactId and version match with the projects you have open in Eclipse. So if the project you depend on has version 1.0.0-SNAPSHOT in Eclipse, make sure that the depending project's POM file references version 1.0.0-SNAPSHOT in the dependencies section.
Enable Workspace Resolution for each of the projects. Right-click the project, then Maven > Enable Workspace Resolution.
Finally, if the projects are still not resolved, right-click the project again, then Maven > Update Dependencies
This should solve your problem.
I had the same issue and resolved the problem by right-clicking on the project and selecting Maven -> Disable Workspace Resolution from the context menu. I had already tried updating the project from the POM file as described above.
In order to fix this typically you can copy the Eclipse .classpath file from a working project since there isn’t anything project specific here assuming you’re structured as a standard Maven project. This will tell Eclipse to allow Maven to manage the dependencies and build. There seems to be no easy way to do this from the Eclipse UI.

maven dependencies to a parent project build path in eclipse

I am using m2e. So I have two projects. When I right click on them both have maven enabled. So one of the projects is a parent project so it has many sub packages each sub package is correctly src\target, but not the parent itself. I have pom.xml for parent and all the children.
When I right click on these two projects then maven then update configuration. The maven repository gets added to the simple project but not to the one which is a parent of the rest. So what should I do in this case?
You have to perform a mvn install for the artifacts to get installed in the repository, the "update project configuration" is similar to the mvn eclipse:eclipse goal of the maven eclipse plugin.

m2eclipse not finding maven dependencies, artifacts not found

I'm using m2eclipse as my maven 2 plugin for eclipse. I'm brand new to maven, so my mistake might be simple, although searching has not yielded any solutions for me. I can run maven from the command line and it build successfully. However if I import as an existing maven project, or use mvn eclipse:eclipse and then import I get the artifacts not found in my POM file resulting in no maven dependencies being loaded at all.
What's odd is that I have 2 projects, both children to a parent pom packaged project. One child loads all my maven dependencies while the other cannot find any and says my pom file is missing artifacts. Again, I can install and package them all just fine from the command line.
I even tried loading my projects into netbeans which worked flawlessly, however I am required to use eclipse.
Any ideas on how to fix this?
Update
Directory structure, pom files layout:
--main
--pom.xml (is a pom package that is the parent to two other projects)
--ProjectA
--pom.xml
--ProjectB
--pom.xml
Main is the parent project of both ProjectA and ProjectB. ProjectB has ProjectA as a dependency. Apprently m2eclipse is not happy about that depedency. As soon as I remove the dependency of ProjectA from ProjectB's pom file all the maven dependencies are found by eclipse.
- com.company.myproj:app:6.6.0:jar Missing: ---------- 1) com.company.myproj:main:pom:${myproj.version} ---------- 1 required artifact is missing. for artifact: com.company.myproj:main:pom:$
{myproj.version} from the specified remote repositories: apache-incubating (http://people.apache.org/repo/m2-incubating-repository/, releases=true, snapshots=true), central (http://
repo1.maven.org/maven2, releases=true, snapshots=false)
However, I still need ProjectB to have that dependency for ProjectA. The error message seems to be m2eclipse looking for ProjectA in a remote repo. Project A should only be in .m2 directory, but I'm not sure how to tell m2eclipse to look there.
I think this may be just a m2eclipse specific issue because using mvn from the command line works fine and like I said previously, netbeans loads the projects and dependencies just fine.
I had this issue for dependencies that were created in other projects. Downloaded thirdparty dependencies showed up fine in the build path, but not a library that I had created.
SOLUTION: In the project that is not building correctly, right-click on the project and choose Properties, and then Maven. Uncheck the box labeled "Resolve dependencies from Workspace projects", hit Apply, and then OK. Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies) and your errors should go away when your project rebuilds (automatically if you have auto-build enabled).
It sounds like your m2eclipse install is using the embedded Maven, which has its own repository (located under user home) and settings.
If you open up the Maven preferences (Window->Preferences->Maven->Installations, you can add your Maven installation by selecting Add... then browsing to the M2_HOME directory.
(source: sonatype.com)
For more details see the m2eclipse book
For me maven was downloading the dependency but was unable to add it to the classpath. I saw my .classpath of the project,it didnt have any maven-related entry. When I added
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
the issue got resolved for me.
One of the reason I found was why it doesn't find a jar from repository might be because the .pom file for that particular jar might be missing or corrupt. Just correct it and try to load from local repository.
Okay I fixed this thing. Had to first convert the projects to Maven Projects, then remove them from the Eclipse workspace, and then re-import them.
I had problems with using m2eclipse (i.e. it did not appear to be installed at all) but I develop a project using IAM - maven plugin for eclipse supported by Eclipse Foundation (or hosted or something like that).
I had sometimes problems as sometimes some strange error appeared for project (it couldn't move something) but simple command (run from eclipse as task or from console) + refresh (F5) solved all problems:
mvn clean
However please note that I created project in eclipse. However I modified pom.xml by hand.
This could be a problem if you are using a custom 'Settings.xml', with a different <localRepository> configured in it.
Eclipse will be using the default installation of MAVEN, and will be using the default location for the User to look for the local Maven repository, which on Linux systems would be '/home/${USER}/.m2/'
Eclipse can be easily configured to use the customized 'Settings.xml', by doing the following:
Goto -> Window -> Preferences -> Select 'Maven' -> Select 'User Settings'
Under 'User Settings', select the custom 'Settings.xml' file, for 'User Settings' by clicking 'Browse' and selecting the customized 'Settings.xml'.
Click on 'Update Settings', if the 'Local Repository' Textbox does not show the custom location from the file above, just key in the location and click 'Reindex'.
Click 'OK'
After this, you could proceed to select your project from the 'Project Explorer', right click, Select 'Maven' > 'Update Project'. Make sure that your project is selected (ticked) in the Window, and click 'OK'.
This should help to resolve the issue, if using custom 'Settings.xml' for Maven.
Hope it helps.