I'm currently working on creating a Maven-Tycho build environment for a relatively large RCP project. The Maven build is already completing successfully, but I'm having trouble removing all the errors from the projects when opening all the sub-projects in the Eclipse IDE.
One of the problems that is most common is, that a MANIFEST.MF contains a Require-Bundle line that cannot be found. This is mostly because I'm using the tycho-pomless extension to reduce the number of pom files I need to maintain.
So the error that happens is, that it cannot find a dependency in the Manifest, because the project should inherit it from the parent-pom. Because it is a pomless build though, the temporary pom for the project is only existing while building the project with tycho-maven. This means that eclipse does not seem aware of the inheritance of the dependency.
I've created a minimal example HERE.
If you open this workspace with an Eclipse IDE you can see, that there are errors and the following lines in App.java have errors:
import com.github.oxo42.stateless4j.conversion.ParameterConversion;
ParameterConversion.validate(null,null);
The required dependency is in the parent pom in the root directory of the workspace:
<dependency>
<groupId>com.github.oxo42</groupId>
<artifactId>stateless4j</artifactId>
<version>2.5.0</version>
</dependency>
The dependency is also in the Manifest of module 1, but it cannot be found in the Eclipse IDE.
If you try to build the project with Maven from a shell, you will notice that the dependency inheritance is honored, even without test.module1 having a pom file and the build succeeds.
So the current state is: CLI Maven build is working, but Eclipse IDE cannot resolve the dependencies correctly making development a bit of a mess.
Is there a way around this, or will I just have to create a pom file for those specific modules?
Related
In Intellij IDEA 2017.2, I am trying to import an existing multi-module Maven project which builds fine outside the IDE via Maven. When the import is complete, I noticed that in one of the Maven submodules, a symbol is unresolved, lets call this submodule submodule-problem. The unresolved symbol is a class that is defined in another submodule, lets call that submodule-other. The thing is that in submodule-problem, other classes defined in other submodules at the level of submodule-other are found ok(those submodules are defined as dependencies in the pom file of submodule-problem). Furthermore, submodule-other isn't declared as a dependency in submodule-problem's pom file. But I should NOT have to do this because as I mentioned mvn clean install -Dmaven.test.skip=true works fine. So does mvn test-compile. I am using the latest Maven 3.5.0 and have instructed IDEA to use the same for the said imported project in the project's Maven settings. Note: I don't have permission to show the code or concerned POM files.
Things I've tried to resolve the issue so far are:
Invalidate caches and restart IDEA, many times
Re-import as Maven project, many times
Delete the .idea folder and all *.iml files from the said project and re-import as Maven project, a few times
Delete IDEA's system preferences folder and retry all previous steps again many times (this step was painful as I had to install all my plugins and configure IDE setting over again)
Imported the same project into Eclipse-Oxygen and saw that it doesn't have any issues with the importing of the project.
I have solved the problem. It turns out that it wasn't any problem with the IntelliJ IDEA IDE (at least I think not). In production, my top level project is a child project of another parent Maven project and so it's version in it's pom file references the parent's version using ${project.version}. Whereas in development it IS the parent with the lower level projects being it's own children. So in all pom.xml files, where ${project.version} was being used by my top level project to refer to the production parent and also in the children poms where they were referring to my top level project as their parent, I changed it to something like a literal like 1.0.0-SNAPSHOT and all problems went away, I didn't even have to re-import the project into the IDE.
Now, as I mentioned in the original post, even without having to do this, Maven had no problem building the project. I'd love to know why if anyone knows. Perhaps the IDE needs me to do this because it is trying to enforce some best practice? I was led to the solution by watching idea.log where it complained about some POMs being invalid and indeed in those pom files the version tag had a red squiggly underline.
I had a GWT app, and I wanted to automate its build and deploy system, since I do it manually. But I did not find a way how to build the app from command line, so it can than be automated. I had to click the Google button, then compile GWT project and then click Compile.
I found out that it is possible to create a GWT maven project and that it should then be possible to compile my project from commandline with mvn gwt:compile.
So I created a new project using this plugin. Copied my sources from the old project to this new one.
Now the structure is like this:
/src
---/main
------/java -> here are all my sources including my Project.gwt.xml file.
------/webapp
---/test
pom.xml
Now I have 2 problems.
1. I thought that I add dependencies to the pom.xml, and then when I build the app, it will create the jars and I can use those libraries in my GWT app. I guess 'mvn clean install' should do this, but so far I'm getting compile errors.
2. I did not get mvn clean install to work, so I added all the jars manually again... And then yes! I was able to build the app using the plugin GWT button! So I was thinking that now I can use 'mvn gwt:compile', but it fails with:
Unable to find: "com/company/project/Project.gwt.xml" on your classpath; could be a typo, or maybe you forgot to include a classpath entry for source?
EDIT:
So I fixed my <moduleName> element in pom.xml, so now it finds the Project.gwt.xml. I'm trying to run:
mvn clean install gwt:compile
But I am getting compile errors. I think, it tries to build my project without the actual dependecies because it tells few classes don't exist, but those classes are part of an external library. (specifically this one). But I have it in the dependencies, so I don't know what more to do.
<dependency>
<groupId>com.github.tdesjardins</groupId>
<artifactId>gwt-ol3</artifactId>
<version>3.0.0</version>
</dependency>
Also in eclipse I had to manually add the jars to my project, so that was why it worked there and not in the command line. So I would also like to ask how to tell eclipse to get those jars and include them to the project, because otherwise eclipse is missing those dependencies and displays many errors.
First I had a problem with <moduleName> in my pom.xml was missing com.company.project prefix before the actual module name.
Then I had errors in my Java files, which was caused by RELEASE version of GWT-OpenLayers 3 library missing some of the features that I previously used by building the JAR from the GitHub repository.
I started working on a Dynamic Web Project some time back and now I'm almost in the stage of finishing it. I have used a number of jars in my project which I have used by downloading the jars manually and then adding them to the build path in Eclipse
Now my requirement asks me to convert the project to a Maven Project which I did using Eclipse. The pom.xml is empty now.
Is there anyway I can automate the addition of <dependency> of the jars which I have used in my project to the pom.xml ?
Or do I have to manually search for each jar in the repo and then add its dependency in the pom.xml?
I have also customized some jars to suit my application. So I will skip adding them to the pom.xml obviously. But that jar has some dependencies on other jars which are used as it is; which can be obtained from the maven repo.
I could not find anything related to this on Google or Stack Overflow.
This feels like a really stupid question but I haven't been able to find an answer.
I'm working on a maven project but I do most of my development in eclipse. Is there any way for me to force maven to generate all of my dependencies under target even if there are errors in the code? I set my eclipse project's build path to use the jars under target/dependencies/jars, but calling mvn clean kills them and if there are any errors in my code causing it to not compile mvn package won't create the dependencies but will instead just crash saying BUILD FAILURE. This makes the problem even worse since instead of seeing the actual errors my eclipse will just bombard me with errors everywhere since all of its dependencies just died.
Or maybe the way I'm working with it is just stupid and there's a better way.
Are you using the m2e plugins for Eclipse to process maven projects, or simply importing the projects as general ones?
If the latter, you should use the m2 plugins (simply go to the Eclipse Marketplace and search for Maven), as they interrogate your POM and set up your dependences properly. You can then concentrate on any compile errors in your code.
You should not point to the jars in the target folder for dependent JAR's since this is where the products of building your project are stored. Performing a mvn clean removes this folder.
To use Maven with Eclipse install the m2e plugin in Eclipse. This makes Eclipse understand the structure of Maven projects.
Once installed you can import your Maven project into Eclipse. I use Import... | Existing Maven Projects for this. But you can also directly import form a versioning system.
During the import Eclipse will set up the Eclipse project to use the Maven dependencies to locate the required JAR's. These are taken from the repository as configured with the used Maven installation.
I guess I haven't really had to do this much before because I am running into a strange issue. I am trying to generate a JAR from an existing Java project and then and putting it into a Spring Maven project. I'm sure I'm including it correctly, I have done this many times before with 3rd party JARs that I get (even though its a Maven project I have included some obscure JARs in it and put on buildpath, etc), with my JAR within Eclipse it is showing up fine as if its included, I have a test class that is importing a class from the JAR, instantiating it, etc and its not showing any errors (imports are fine in the IDE, etc), however when I go to do a Maven install I get:
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[11,15] package org.test does not exist
[ERROR] /media/src/main/java/org/jadefalcon/automation/DataSetup/test.java:[21,2] cannot find symbol
I have tried doing a Maven clean but still the same problem, the JAR class I am testing with is this: (was trying a more complex one but then tried this to troubleshoot the issue)
package org.test;
public class something {
public String main () {
return "it is definitely working fine";
}
}
Here is the JAR I generated (with sources visible):
https://docs.google.com/leaf?id=0BzB_xvrbRpbYODQyMjEzOWEtOTdjNS00YjM3LTlkZGUtNjY5NmIwN2RiNTRj&hl=en
I would appreciate any advice as I am rather perplexed and frustrated by this. Thanks
You can include a 'regular' jar in your maven project -just as you described- though it's not a best practice mainly because then you not even lose the functionality of Maven for that jar, but also the whole point of Maven dependency management: you will have to include that jar with your source to make it build.
You can of course also create a Maven artifact for that jar, build it with Maven, install it with Maven and use it as a normal Maven dependency.
You also can create a parent .pom and have your dependency project as a module in it and also your real application (or also your real app can be your parent). See further here.
Since this caused me quite a bit of grief, I figure I should post the solution I found. Apparently you aren't supposed to just include a regular lib JAR in a maven project (although I swear I have done it before and it worked), I found this way to include a local JAR that isn't form a repository from this post:
Can I add jars to maven 2 build classpath without installing them?
I did this and its doing the maven install properly (where version and artifactID are just made up value)
<dependency>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/testjar.jar</systemPath>
</dependency>