My pom.xml has scm configuration as follows
<scm>
<url>${my.scm.url}</url>
</scm>
I have property file which I am reading using properties-maven-plugin which has the value of ${my.scm.url}, and also I am using buildnumber-maven-plugin to get latest revision from SVN.
The issue is buildnumber-maven-plugin throws invalid scm url error but, when i replace ${my.scm.url} with actual url to my svn repo , it works perfectly.
How can I achieve successful execution without having to hard code scm url ?
PS: I run build using : mvn clean install command.
The problem is probably due to the order that the plugins run. The following should work:
Bind the properties-maven-plugin to the initialize phase
AFTER that plugin configuration in the POM, add the buildnumber-maven-plugin plugin
AFTER the previous two, put the buildnumber-maven-plugin plugin (which by default bind to the initialize phase).
Now all 3 plugins should run in the correct order (you can check this from the logs). Alternatively you can bind the to different phases to ensure that they run in the correct order, but the above should be enough and conforms with the goal of the initialize phase (initialize build state, e.g. set properties or create directories).
Because you didn't post the POM file, I'm guessing a bit.
Obviously, the order is going to matter, you must get the properties loaded first. That said, looking at the mojo, I'm not sure setting properties is the equivalent of essentially setting a -D.
If you did a mvn -Dscm.url= clean install, then the value would be there because it's being defined to the mvn JVM. Depending at what point the ${scm.url} is being evaluated, if it's before the properties mojo has a chance to run, it's going to be too late.
If you use a CI tool (i.e. Jenkins, Hudson) that can load the properties before the mvn call, then the variable is defined.
I've used the buildNumber mojo for my builds, because I have buildNumbers automatically generated for my snapshot artifacts. The order things occurred:
property file is downloaded from Jenkins master to slave for this job
Jenkins plugin loads the properties file into the job
maven build starts, the build number is already defined before mvn is called (again, behaving like a -D) and my buildNumber is incorporated into my artifact version
buildNumber mojo causes the property file to have buildNumber incremented
property file copied back to Jenkins master
I also wanted to load the properties file within maven and have it "update" the artifact id on the fly, but by that point, Maven had already evaluated; hence, I had to do it beforehand.
Hope this helps.
Related
I want to spare the time typing a -T3 on the command line as I want all the maven builds I will ever do to run multithreaded.
Maven 3.3.9
I googled but didn't find anything promising, only the suggestion to add an environment variable for command line opts and append that to every maven call on commandline.
Maven: configure parallel build in pom.xml
This way, every time, still a manual step is required (entering the environment variable's name) to do a parallel build.
I'd like to configure that globally in the mvn settings.xml file.
You can't configure thing like this settings.xml. This can be configured differently since Maven 3.3.1.
You can use a file ${maven.projectBasedir}/.mvn/maven.config which contains the options given on command like within the root directory of your project which simply can contain:
-T 3
but this is limited on a project base not always.
I would need to execute a specific Maven plugin from command line. For example, in the following I execute a specific version of Maven Surefire Plugin to test Java projects:
mvn org.apache.maven.plugins:maven-surefire-plugin:2.19-SNAPSHOT:test
However, the above assumes to find the surefire plugin 2.19 in the default Maven repository path. Now, my question is, if I want to use the plugin with a specific path (not Maven default one), what should I do using the command line? I would expect something like the following, without modifying pom.xml:
mvn /path/to/some/jar/version/org.apache.maven.plugins:maven-surefire-plugin:2.19-SNAPSHOT:test
or more generally, for the following invocation
mvn groupId:artifactId:version:goal
I would need somewhere to specify a customized path to execute its goal
mvn /some/path/to/groupId:artifactId:version:goal
On the other hand, please let me know if this is not even supported by Maven.
This is not how it works. Maven will always look-up artifacts inside your local repository. And if it can't find it in your local repository, it will try to download it from configured remote repositories.
As such, you don't specify a path to a plugin. You specify a path to a local repository, where that plugin is installed. In this local repository will be installed all the dependencies of the plugin you're trying to invoke. This also means that you cannot have a JAR to a plugin "sitting around" anywhere; it needs to be located inside a correct repository tree directory. With a local repository of /my/local/repo, the artifacts of the plugin groupId:artifactId:version must be located in /my/local/repo/groupId/artifactId/version and be named artifactId-version.jar (and .pom). In the same say, the location of the dependencies of that plugin must follow that directory structure.
By default, the local repository is located inside ~/.m2/repository. But you can change that by:
Specifying the maven.repo.local system property on the command line, for example with mvn -Dmaven.repo.local=/path/to/local/repo groupId:artifactId:version:goal;
Use a custom settings.xml and tell Maven to use it with the -s command line option. It would contain:
<settings>
<localRepository>/path/to/local/repo</localRepository>
</settings>
and be used with mvn -s /path/to/settings.xml groupId:artifactId:version:goal
I am trying to deploy signature files separately using deploy-file goal to Nexus staging repository, but I noticed that mvn deploy plugin removes the extension. My file is something like: azerty-0.1.jar.asc
but the file that gets deployed is: azerty-0.1.asc
I tried adding a classifier: -Dclassifier=jar
the file that gets deployed is: azerty-0.1-jar.asc
This seems like a strange behaviour.
Question: Any ideas how to work around it?
This is rather a normal behavior, Maven is using the file extension as artefact packaging, from maven-deploy-plugin, deploy-file, packaging option:
Type of the artifact to be deployed. Retrieved from the <packaging> element of the POM file if a POM file specified. Defaults to the file extension if it is not specified via command line or POM.
Note: bold is mine.
Moreover, the classifier option would indeed add an - between the version and the string provided as classifier: that's maven convention.
In your case you want to specify a special packaging, which would be jar.asc if you really want the remote file to have as extension jar.asc.
The following would hence work:
mvn deploy:deploy-file -Dfile=azerty-0.1.jar.asc -Dpackaging=jar.asc -DrepositoryId=your_id -Durl=http://your_repository -DgroupId=your_groupId -DartifactId=azerty -Dversion=0.1
Note the -Dpackaging=jar.asc which effectively tells Maven the file extension would be jar.asc.
As a general note, if you are using the repository as a build store, that would still be reasonable, otherwise in your case you would push to a Maven repository an artifact which would then be difficult (or rather weird) to import in a project.
If instead this is really an additional artifact of your project, you should look at the attach-artifact goal of the build-helper-maven-plugin, to effective define it as additional artifact, then Maven will automatically add it to its install and deploy phase.
I created a mvn build with the goal set as dependency:list
I want to see file sizes, so I tried passing in depedency:list -Darguments=-DdependencyDetailsEnabled=true
also
depedency:list -DdependencyDetailsEnabled=true
and lastly I did dependency:list and added a parameter called dependencyDetailsEnabled with value of true
none of these displayed file size for the dependencies. My wish is to see total file size of all maven dependencies for a project, but I can only find that I can list per jar with the above command, and even that is not working.
I think you might be looking for the Maven Project Info Reports plugin. Running this as
mvn -DdependencyDetailsEnabled=true project-info-reports:dependencies
will create a dependency report with file sizes (as well as other metrics). You'll need version 2.1 (or later) of the plugin.
Cheers,
Using İntelliJIdea, I Downloaded my project from Subversion for 12 times.
Deleted .m2/repository for 7-8 times.
Reimported, downloaded source for 15 times. Tried every possibilities but still cannot run my project.
Here is my Maven run profile and project hierarchy
and here this is my maven output
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven.plugins:maven-clean-plugin:jar:2.5 has not been downloaded from it before. -> [Help 1]
http://paste.ubuntu.com/10613835/
There is nothing wrong with project or maven files. I'm running it on my work computer. But not in my personel.
Update1: After I deleted "-o" parameter in maven run configuration. Here is my new log Logs after deletig "-o" paramter and here is image url http://i.hizliresim.com/Lp6dDJ.png
Update2: I run this command on cmd,
C:\MAYA\MAD4>mvn dependency:tree -Dverbose the result is success. And also saw C:\Users\tayfuny\.m2\repository\org\codehaus\plexus\plexus-digest\1.0\plexus-digest-1.0.jar in my dir. Here is latest maven output http://i.hizliresim.com/XBgD07.png
Update: Its early in the morning here in Switzerland - i have overseen you specified the -o parameter in your run configuration in the section Command line:. This is the console parameter to let Maven work offline ;) Remove it and you should be all good. Source: http://books.sonatype.com/mvnref-book/reference/running-sect-options.html
Update 2: Alright the initial problem is solved - your log however shows two more things to fix (one of them optionally but very recomended): 1.) The warnings at the very start of the build imply you have duplicate dependency/version declarations - those should be easy fixable. You can for example use mvn dependency:tree -Dverbose to get a overview on the duplicates (and which definition takes place in the end). The second is a actuall build error. I dont know about the install plugin you are using but i guess that you are missing this dependency: http://mvnrepository.com/artifact/org.codehaus.plexus/plexus-digest/1.0 (or another one containing the class that could not be found - adjust version as needed as well).
Answer regarding offline mode:
Remove the parameter -o when running maven unless you want to work in offline mode and with your local repository only.
Another probable cause is explicitly setting Maven to work in offline mode (e.g. only consult the local repository to resolve dependencies) from within the IDE itself (which will result in calling Maven with the -o parameter behind the scenes).
General Settings/ Project Settings:
File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven
(The very first option Work offline should be deactivated/ deselected unless you realy want to work with the local repository only).
Those settings are inherited by Maven-run configurations by default but may be overwritten at two levels
Default Run Configuration:
(Those default configs will be inherited by specific run configurations. Note that changes to the general settings apply to newly created run configurations only and will not be populated to existing ones).
Specific Run Configuration:
Make sure none of the options is selected. In the end if you use a specific launch configuration make sure the option is not selected in that specific configuration and change the higher levels for convenience if it makes sence)
EASY WAY
This should work for all similar errors.
This is how an error looks like
Could not resolve : org.apache.maven.plugins:maven-clean-plugin:jar:2.5
Could not resolve : (groupID):(artifactID):version
So what you actually need is a correct version of the clean plugin.
<dependency>
<groupId>(groupId)</groupId>
<artifactId>(artifactId)</artifactId>
<version>(version)</version>
<type>maven-plugin</type>
</dependency>
This will become something like this. Add this to dependencies section Pom.xml. Reload build.
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<type>maven-plugin</type>
</dependency>
Reload build and IDE will automatically download these version of artefacts and
replace if there are other versions because your project needs these particular versions to run.
Do the same with other dependency errors. "Works every time".