Hi all I'm new to apache maven. I imported a project into netbeans everything seems well but i get this error when trying to build it:
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
Property "loadVersion" is required for this build.
I think this means that the version of one of the dependencies in the pom.xml file are wrong but not sure.
Any help is appreciated.
More detail from the question poster:
I'm working on a small part of a project and the part I'm working on has a pom.xml file. This file doesn't have any enforcer rules. However the top level (or highest level pom.xml file) does have an enforcer rule with the required version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0-beta-1</version>
</plugin>
Shouldn't this be enough?
More details from the OP:
It seems I could have just commented this line out in the top level pom file:
<requireProperty>
<property>loadVersion</property>
</requireProperty>
But then I would get other errors. I then read the project sites thoroughly and found out that the project's code can and only should be built with their provided build scripts. When building with their scripts the build is successful. This is good and bad it because now I have to edit code in the IDE and then build it in the terminal, but at least it's a solution.
Your project is using the Maven Enforcer Plugin which is somewhere configured (in a parent POM, in an active profile) to "enforce the existence and values of properties" using the requireProperty rule, in your case a loadVersion property.
Declaring such a custom property with Maven can be done in a pom.xml directly under the project element or in a profile or in a profile in the settings.xml by adding the following:
<properties>
<loadVersion>someValue</loadVersion>
</properties>
And this property can then be referenced by ${loadVersion}. I have of course no idea of the value that should be set.
See also
POM Reference
The complete reference for the POM structure
Settings Reference
I'm going to guess that your pom.xml uses the enforcer plugin and that you have not defined the loadVersion property as per the rule constraints.
Related
We are using a Maven for a while in our project and want to automate the release process little bit. we came up with the following idea so that the version will be maintained by developers or in SCM instead of in DevOps tool like jenkins/bamboo.
Anyone following below process instead of setting the interpolation value in arguments as "mvn install -Dapp.version=1.0.0-SNAPSHOPT"
The process we like to follow is to supply the Maven project version through an external property file.
let's assume the following partial POM.xml excerpt as example.
<project>
<groupId>com.home.diary</groupId>
<artifactId>journal</artifactId>
<version>${app.version}</version>
<packaging>war</packaging>
</project>
let's assume i have an version.properties file in my SCM with following content
app.version=2.0.0-RELEASE
while running the mvn goal
mvn install
i want the artifact generated as
journal-2.0.0-RELEASE
I tried using plugin properties-maven-plugin from org.codehaus.mojo
as discussed here How to read an external properties file in Maven
but it's not working.
Anyone did this? could you please share your implementation/ideas?
This is not possible.
First of all: Why not just manage the version in the <version> tag itself? It is the easiest thing and fulfils your requirement (the developer manages the version in the SCM).
If you don't want this, you need to supply the version either in the POM itself or through the command line. Reading external properties with something like the properties maven plugin will always happen too late, i.e. after the version tag is already read.
I am building my project with maven-shade-plugin and Netbeans 8.0 is complaining with the following warning:
Project's main artifact is processed through maven-shade-plugin
When the final artifact jar contains classes not originating in current project, NetBeans internal compiler cannot use the sources of the project for compilation. Then changes done in project's source code only appears in depending projects when project is recompiled. Also applies to features like Refactoring which will not be able to find usages in depending projects.
How can I fix this? What can it break?
I found a "fix" by following the instructions over in Apache's Maven Docs
I added the following to my pom in the shade plugin section.
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName> <!-- Can be any name that makes sense -->
</configuration>
I now have 2 artifacts but it works for my needs.
typically it's a problem in projects depending on this one.
While the jar file in local repo contains classes from it's own dependencies, the src/main/java folder doesn't contain them. That confuses the java engine when it attempts to re-compile the changes done locally in the editor.
there is no way to "fix" it. it's been placed there after repeated bugs were filed against the editor showing compile errors where there were none. I think there is an issue filed for letting the user have the warning disappear.
I'm using the maven ci friendly style to set the pom version from a property. Before I get into the details of what's happening, let me tell you how my pom and project is structured.
Project structure
base-project-pom
|_ reactor-parent
|_ service
|_ service-tests
base-project-pom has a plugin called maven-enforcer-plugin which executes during validate phase.
In reactor-parent pom (pom packaging), I'm setting up version using following code -
<groupid>...</groupid>
<artifactid>...</artifactid>
<version>${revision}</version>
<properties>
<revision>0.0.1-SNAPSHOT</revision>
</properties>
I'm using same ${revision} tag in two leaf projects i.e., service and service-test.
The problem is maven-enforcer plugin is unable to determine ${revision} tag.
This is the error message (dropped confidential part such as url) -
Failure to find ....service:reactor-parent:pom:${revision} in http://... was cached in the local repository
com.example.service:reactor-parent:pom:${revision}
In order to get rid of this problem, I've tried following different solutions -
1. Using maven-flatten plugin -
I've tried using this plugin to flatten the pom. It didn't work. It seems to me that the issue could be related to the phase during which these two plugins (flatten and enforcer) are executed.
2. Executing enforcer during different phase
Flatten is executed during process-resources phase while enforcer is executed during validate phase. I've tried executing enforcer during verify phase and install phase. It didn't work.
3. Revision property tag in the leaf projects.
I've tried setting up property tag for revision in the leaf project. That hasn't worked either.
Any pointers or direction is appreciated.
Updated (29-May-2018) - As of today, I'm seeing that this is known bug in maven-enforcer plugin.
Issue Tracker
I am building my project with maven-shade-plugin and Netbeans 8.0 is complaining with the following warning:
Project's main artifact is processed through maven-shade-plugin
When the final artifact jar contains classes not originating in current project, NetBeans internal compiler cannot use the sources of the project for compilation. Then changes done in project's source code only appears in depending projects when project is recompiled. Also applies to features like Refactoring which will not be able to find usages in depending projects.
How can I fix this? What can it break?
I found a "fix" by following the instructions over in Apache's Maven Docs
I added the following to my pom in the shade plugin section.
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName> <!-- Can be any name that makes sense -->
</configuration>
I now have 2 artifacts but it works for my needs.
typically it's a problem in projects depending on this one.
While the jar file in local repo contains classes from it's own dependencies, the src/main/java folder doesn't contain them. That confuses the java engine when it attempts to re-compile the changes done locally in the editor.
there is no way to "fix" it. it's been placed there after repeated bugs were filed against the editor showing compile errors where there were none. I think there is an issue filed for letting the user have the warning disappear.
I'm looking for a maven plugin that will help me manage version names and codes of every build that is made on our CI environment. Something that will be able to attach a prefix to the main version code or even update it (not changing the pom.xml). For example:
project version: 2.0.1
git/svn revision: 2342334
jar output: name-2.0.1-2342334.jar
maven repo: ../path/to/local/maven/repo/<package path>/2.0.1-2342334/
The main requirements to this plugin are:
Must be in Maven Repository (which means that NO additional setting required to add this plugin in my pom.xml and run maven)
Must not edit the pom, each time it's applied
A configuration file, would be great, so I could manage the versioning process
Must be able to edit the output file metadata (so the version will be applied as if it was written in the pom.xml file in the first place)
So far I found only maven-buildmetadata-pluging but unfortunately it's not in Maven Repo, so I'm stuck. Any help would be great.
Hosting your own maven repository is very easy, using either Nexus or Artifactory. You can also use the Artifactory cloud version (I'm not affiliated with them...) so it may solve your problem. BTW - a simple server with Apache does the trick as well, but with more work..,
Regarding the plugins: If you deploy snapshot applications then each gets its own version based on timestamp.
For releases another option is to run an svn info and put the result (or part of it) into the generated artifact. The information can then be accessed by the code.
If you change the version of your artifact the pom has to reflect the change, cause otherwise it's not reproducible.
If you change something in your build process (like added versions, whatever) it has to be reflected in the pom file. Otherwise you can not reproduce the build process with the same result.
You have written not to change the pom file but maintaining a separate file. So the questions is: Why not using the pom file itself, cause it's intended exactly for that purpose.
Furthermore all informations which you mentioned by the maven-buildmetadata-plugin can be achived by using existing maven plugins (like build-helper-maven-plugin, buildnumber-maven-plugin).
The SCM information can be used by using the buildnumber-maven-plugin which provides information like SCM revision number (SVN or GIT hash).
An on the other hand if you don't like to change your pom file manually you can use either the versions-maven-plugin or the maven-release-plugin which automatically can change informations in your pom file and handle all these things automatically.
To maintain metadata in your producted artifacts you can configure all plugins (like ear, war, jar) etc. more or less like this where the buildNumber is comming from buildnumber-maven-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<index>true</index>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<buildNumber>${buildNumber}</buildNumber>
</manifestEntries>
</archive>
</configuration>
</plugin>
And of course if you really like to use Maven you should have to use an repository manager as already mentioned like Artifactory or Nexus which make life easier.
I just would like to add (although the question is 5 years old and already has an accepted answer) that the Buildmetadata Maven Plugin was not available on the Maven Repo at first, but it is now (since late 2013). People who would like to give it a try find the artifact at the following locations :
com.redhat.rcm.maven.plugin:buildmetadata-maven-plugin
de.smartics.maven.plugin:buildmetadata-maven-plugin
Please note that the name has changed from maven-buildmetadata-plugin to buildmetadata-maven-plugin due to naming conventions.
I'm one of the "original" authors of this plugin at smartics. If you would like to use it, you probably would like to use the fork provided by Red Hat. To my knowledge the two versions do not differ very much and they have not been synced since there is just so much other stuff to do and the plugin seems to be feature stable. ;-)
The source code for both versions is also available on GitHub:
release-engineering/buildmetadata-maven-plugin
smartics/buildmetadata-maven-plugin
As already stated, you have to change the version in the pom. One way of doing that, in combination with the release plugin is:
mvn \
se.bjurr.gitchangelog:git-changelog-maven-plugin:VERSION_HERE:semantic-version \
release:prepare release:perform
Using Git Changelog Maven Plugin