on my Windows machine I do have several proeject that I build with maven. At the moment they are all in SNAPSHOT-State. When I build a project that relies on one of the other projects maven always adds the class files of the other projects to the jar.
If I build the project on my CI-Server this problem does not occur. Does anyone have an idea why maven adds the class files to my jar?
I'm using maven 2.2.1
When I build a project that relies on one of the other projects maven always adds the class files of the other projects to the jar.
This is not a default behavior and, if it happens, you're somehow telling Maven to do so. If you want to hunt potential discrepancies, check the effective-pom, the effective-settings, the active-profiles using the following goals on both machines:
help:effective-pom
help:effective-settings
help:active-profiles
Also double check how Maven is invoked on the CI machine (extra command line parameter, etc).
Related
I create a simple sample Spring MVC project, where IntelliJ 14 by default generate a pom with
<properties>
<spring.version>4.1.4.RELEASE</spring.version>
</properties>
I change it to
<properties>
<spring.version>3.2.0.RELEASE</spring.version>
</properties>
and choose Maven -> Reimport, I can see the dependencies are downloaded to my local .m2 folder
However, when I expend lib folder, all dependencies stays with previous version:
How can I get the latest dependencies showing in \lib folder? I tried to synchronize current project, but it doesn't help this matter
UPDATE
here is my maven setting
UPDATE 2
I forget some detail, which is I create a Spring MVC project in the beginning(so I think it may not be a maven project at the moment), then I right click pom.xml and set current project to maven project.
So I think the jar files listed in \lib folder may be downloaeded via intellij for Spring MVC application, however when I set current project to maven project, it does not remove or update the jar file under the \lib folder.
You should do:
1. Choose menu File \ Project Settings..., In section Build, Execution, Deployment \ Build Tools \ Maven \ Importing, check Import Maven projects automatically. It means IntelliJ IDEA will Synchronize Maven project model and IDEA project model each time when pom.xml is changed.
2. Try closing project, restart IntelliJ IDEA, then reopen the project.
3. Check your internet connection.
IntelliJ isn't shouldn't be looking there for your Maven project dependencies. It is should be using the libraries and resources in your .m2 directory instead.
Mind you, I've left those comments struck out on purpose; depending on your configuration, you may accidentally be doing that.
This is a picture of what the Dozer project looks like. It's a Maven project which I cloned a ways back to see how it worked.
You're going to have to check your Project Structure (Ctrl + Alt + Shift + S) to ensure that the libraries that are coming through are prefixed with "Maven:".
If they are, then the files in your lib folder aren't being used by your project.
In all actuality, those are your global libraries (which you can also find under Project Structure > Global Libraries). Any project has access to them.
If that's causing a conflict, consider deleting those JARs from your global libraries. If you need them for another project, consider adding it to the project's local libraries instead.
We have moved from Archiva to Nexus and are still using Maven 2.
We execute eclipse:eclipse locally so that Eclipse .project and .classpath files are generated, based on the dependencies in the POMs, and then we import the projects into Eclipse to do our development. We don't use M2Eclipse for a variety of reasons.
Since using Nexus, we have the problem that projects don't always reference each other in the workspace, rather they reference the respective JAR.
I have noticed that Nexus is appending a timestamp to the JAR name, and the MVN output states, e.g.:
[INFO] Artifact myapp-bom:jar:7.3.0.2.1-SNAPSHOT already available as a workspace project, but with different version. Expected: 7.3.0.2.1-20120508.115037-68, found: 7.3.0.2.1-SNAPSHOT
I get the feeling that is the reason why eclipse:eclipse generates .classpath files which contains JAR references (based on local maven repo) rather than project references. When we used Archiva (and there were no timestamps) then we used to get project references, and that is exactly what we want.
Has anyone else had this problem and how is it solved? I read that maven 3 forces timestamps to always be generated. Again, how do you get eclipse:eclipse to generate sensible .classpath files?
Cheers,
Ant
PS - some of our projects come from different SVN repositories. It seems that if the Eclipse Projects are refernced in the parent pom, eclipse:eclipse creates a project reference, but if the Eclipse Projects are from a different parent pom, but still in the workspace, then it can only generate JAR references.
The problem was resolved by using maven-eclipse-plugin (eclipse:eclipse) version 2.9, rather than 2.8! Doh...
I have an artifact abc which has some tests. I have different versions of abc within my repository. I now want to be able to run the latest tests against the 'old build' of the project.
I tried to add the artifact itself to the test dependencies but this (of course) results in a cyclic reference error of the maven reactor when building the tests via:
mvn compiler:testCompile
mvn surefire:test
Is there any smart way to run tests against a previous old build/artifact?
Must i create a new pom.xml in which i define the solo test execution?
Or should i add a postfix to my current artifact when executing the tests? (This would avoid a cyclic reference error)
Separate the tests out into a separate module/project that depends on the classes it tests. Then create separate profiles where you change the dependency to be on older releases.
The problem I foresee with what you're trying to do is that the package phase comes after the test phase of the maven lifecycle. Which to me implies that maven runs unit tests against the compiled classes and not the physical jar file (generated in the package phase). You'll therefore have to replace the contents of the projects /target/classes folder with the classes in the "older" jar.
I've been seeing odd behaviour from my Maven 2.2.1 installation whilst doing war installs.
Occasionally, I will update a class but the updated version is not packaged up in the artifact produced by mvn install.
So far, I have determined that an updated .class file is produced in the target directory, and that the class of the same name in the produced .war is not the same (different date modified, different size)
Running Maven from the command line with the -X flag produced debug output for the class like:
[DEBUG] *
WEB-INF/classes/mypackage/MyClass.class
is up to date.
I think I've also had the same problem before where the file that was cached(?) was an incomplete compile from Eclipse, causing 'Unresolved Compilation Problem' errors from the Maven build, but a working artifact from an Eclipse export.
How does Maven determine whether a
file 'is up to date' during the
install process?
Where are the files Maven is comparing to?
Can I force Maven to build a package from scratch?
Any other ideas would be appreciated!
So far, I have determined that an
updated .class file is produced in the
target directory, and that the class
of the same name in the produced .war
is not the same (different date
modified, different size)
Just to be sure, the classes should be built under target\classes, not target.
Can I force Maven to build a package from scratch?
You can force a full build by running
mvn clean install
This performs a clean (essentially removes the target directory) before running the install phase.
Also - check for copies of your classes outside of the Maven build directory. In this case as it is a webapp, check src/main/webapp/WEB-INF/classes
I'm building Maven projects via TeamCity/Git and trying to insert the TeamCity build numbers in the pom.xml that gets published to my repository upon a successful build. Unfortunately I can't determine how to publish a pom.xml with the substitutions inserted.
My pom.xml contains info like:
<version>${build.number}</version>
where build.number is provided by TeamCity. That all builds ok, and if (say) build.number = 0.1, then the deployment is a pom.xml to a directory with 0.1. All well and good.
However, the pom.xml that is deployed is the pom.xml without the substitutions made. i.e. Maven is running with a pom.xml with appropriate substitutions, but deploys the initial version and so I get
<version>${build.number}</version>
in the final pom.xml. How can I get the build version number in the pom.xml ?
I wouldn't use this approach because it makes building a project checked out from the SCM not possible without providing the build.number property. I don't think that this is a good thing. Maybe I'm missing something though.
Actually, I don't get what you are trying to achieve exactly (why don't you write the build number in the manifest for example). But, according to the Maven Features on the Teamcity website:
By default, it also keeps TeamCity build number in sync with the Maven version number (...).
Couldn't that be helpful? There is another thread about this here.
Try to use generateReleasePoms property of maven-realease-plugin, maybe that helps a little.