Maven properties in site apt files - maven-2

How can I use maven properties in site APT files? For example I want to use ${project.version} in the index.apt so I can always refer to the latest version without manually changing the index.apt file before deploying the site.

Found it. Just had to rename the apt files to *.apt.vm. Maven then pipes the files through Velocity which can process the properties.

My download.apt.vm looks like this:
Download
{{${sitePublishUrl}}}
where the pom.xml contains
<properties>
<sitePublishBase>http://artifactory.foo.com/mvn/libs-release-local</sitePublishBase>
<sitePublishUrl>${sitePublishBase}/${project.groupId}/${project.artifactId}/${project.version}</sitePublishUrl>
</properties>
Note: custom properties containing a dot (e.g. ${my.repository}) will not work. This is a limitation of Velocity. Instead use something like ${myRepository}.
See also http://maven.apache.org/plugins/maven-site-plugin/examples/creating-content.html#Filtering

Related

Latest nexus release artifact

I have setup a Nexus repository to store our built artifacts, third party dependencies, and home brewed shared source code headers.
I am currently using wget to retrieve the third party dependencies and shared source headers for use while building our software applications (the source for the specific applications are stored in separate git repositories).
When you use wget, you essentially have to know the exact version of the artifact that you want - you must explicitly know what the latest version number is.
Is there another way to retrieve the latest version of an artifact from the maven releases nexus repository without actually knowing what the version number is?
It would be ideal if there was a way to do this using wget instead of maven itself because I don't want to force users to install apache maven just for the purpose of downloading artifacts from nexus.
I think you cannot do it by using curl only. You will need to accomplish other tasks to achieve what you want.
Here is a possibility:
You should first access to maven repository metadata file. (You will find the documentation here: http://maven.apache.org/ref/3-LATEST/maven-repository-metadata/repository-metadata.html)
For instance, let's say that you want to download the latest version of the following maven artifact from maven central:
groupId = javax
artifactId = javaee-api
Download the following file:
http://central.maven.org/maven2/javax/javaee-api/maven-metadata.xml
Its contents will be something like:
<metadata>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<versioning>
<latest>8.0</latest>
<release>8.0</release>
<versions>
<version>7.0</version>
<version>8.0</version>
</versions>
<lastUpdated>20170915063942</lastUpdated>
</versioning>
</metadata>
Then you will need to access the latest tag to retrieve the latest version.
Documentation says the following regarding the meaning of the latest or release tag:
latest String What the latest version in the directory is, including snapshots
release String What the latest version in the directory is, of the releases only
You should find this file also in nexus repositories, and you should use something like xmllint to obtain the value you want. For instance:
curl http://central.maven.org/maven2/jx/javaee-api/maven-metadata.xml \
| xmllint --xpath "/metadata/versioning/latest/text()" -
or
curl http://central.maven.org/maven2/jx/javaee-api/maven-metadata.xml \
| xmllint --xpath "/metadata/versioning/release/text()" -
depending on what you want exactly.
After that, you can use the version information to compose the full URL of the artifact you want to download.
Hope this helps.
Cheers.
Edu.

Can I install several files into one artifact with Maven2 instal:install-file command

I'm developping application with JOGL2 and my favorite IDE Eclipse, also I want to use Maven2 for this purpose. Unfortunately, JOGL2 has no artifact yet. Also, I plan to deploy it as a runnable jar file.
So I want to install JOGL artifact locally : so i'll use the install:install-file command.
But I want to group several jars to make several artifacts, that is :
gluegen-rt.jar and jogl.all.jar as a single artifact named jogl.core
gluegen-rt-natives-linux-i586.jar and jogl.all-natives-linux-i586.jar as a single jar named jogl-natives-linux-i586
and so on
Is it possible ? (The official documentation does not mention the possibility or unpossibility to do so).
Thanks in advance
Install all files as usual like file:jar:version. Than create pom with pom packaging and use gluegen-rt.jar and jogl.all.jar as dependencies in it (they must be already installed). After that use new pom as dependency in your project.
maven doesn't have support for that. You would have to unpack these JAR files and repackage them together.
maven does have support for merging JAR with dependencies (http://stackoverflow.com/questions/574594) - and it's done the way I mentioned above. But you are asking about merging two arbitrary JARs, which is not possible in maven.

Download Maven2 dependency from non-standard layout repository

I need to download a file from a non-standard layout repository.
The standard repository layout is groupId>/<artifactId>/<version>/<artifactId>-<version>.<packaging> however, I need to download the following file:
http://hudson.myserver.com:10000/repo/ocp-services/schemas/trunk/201/archive/schemas/dist/schemas.jar
where ocp-services is effectively the groupId, schemas is the artifactId and 201 is the version.
How would I add a dependency to this file and get it downloaded into my project and local repository?
This is a Hudson file repository if this is of any help, but it is a third parties so difficult to get them to change any location.
One option would be to register a custom ArtifactRepositoryLayout implementation and to declare a repository using this custom layout. I've never done that but it should be possible, check this blog post.
A second option would be to configure Maven to go through some kind of custom proxy (e.g. a Servlet) and to rewrite the URL on the fly for this particular dependency.
In both cases, I'm afraid Maven will complain about missing metadata ("A dependency in Maven isn't just a JAR file", see 3.5.5. Maven's Dependency Management) because the hudson file repository is just not a Maven repository. Maybe this can be handled programmatically though. But as I said, I've never done this.
A third option would be to ask the project building the JAR you need to deploy it (in the maven sense). That would be of course the best solution.
A last one option would be to just download this JAR and to install it manually in your local repository. If this is an option, go for it.
Have you tried adding this to your pom.xml :
<dependencies>
<dependency>
<groupId>ocp-services</groupId>
<artifactId>schemas</artifactId>
<version>201</version>
<type>jar</type>
</dependency>
</dependencies>
or if that don't work as Pascal says install it manually

Activate different Maven profiles depending on current module?

We have a multi module build with modules using different technologies, like Java and Flex. Is it somehow possible to activate different profiles based on the module that is compiled currently?
I tried it with an activation like
<profile>
<id>flex</id>
<activation>
<file>
<exists>${basedir}/src/main/flex</exists>
</file>
</activation>
...
</profile
But it didn't work, although the use of ${basedir} is documented in the Maven documentation (this is a bug in Maven). Is there a different possibility to have different activations based on the current module? Or does Maven only allow to activate a profile for all modules or not at all?
After some more research I finally came to the conclusion that this is not possible for two reasons in the current Maven version (2.1.0):
Maven profiles are not inherited, so you can't define a profile in a parent POM and activate that in a child POM.
I haven't found a possibility to activate a profile from a POM itself. The activation does not work with ${basedir} and the property activation response only to system settings, which are globally specified through the -D option.
For those like myself reading this question looking for answers, this use case now works in Maven 3.
There is was a bug affecting this feature in early versions of 3 (see http://jira.codehaus.org/browse/MNG-2363) but it works for me correctly using Maven 3.0.4.
In 2.2.1, profiles are inherited but the ${basedir} issue is still there. I'm in the same boat - I need to activate a profile based on the existence of a file in a given project. My child builds run individually just fine (inherited profile activated by local file existance), but if I run the build from the top parent, they fail because the file isn't found.
With regard to file-based activation, you can try removing ${basedir}. We use it like this:
<activation>
<file>
<missing>target/jboss/conf/jboss-service.xml</missing>
</file>
</activation>
I dont know if this helps, but I solved a similar problem with the following approach:
I created and described the profile in the parent POM, which has activeByDefault=false. The PluginManagement-Section then contains the configurations for different plugins.
The children can reuse this profile, and set activeByDefault=true
This makes the profile active, but still none of the plugins are activated.
But fortunately the described plugin configurations are available. You can reuse them in children by defining them in the Plugins-Section. You just provide the group- and the artifactID, and set inherited=true for each plugin you want to reuse in the children.
I hope that helps. Sorry for not including any code snippets, but I hope even so the soutions is understandable.
You can set a property in each module that you want to use the profile, and then use "property" activation in your profiles.

maven-buildnumber-plugin

i use the maven-buildnumber-plugin to generate my version number for JAR/WAR/EAR packages. So when doing a compile i'll get for example ${project.version}-${buildNumber}, because is set to this value. But when using mvn deploy just ${project.version} is the filename, samen when i set in pom.xml to XX ${buildNumber} then the filename ist file-XXX ${buildNumber} (<- not the content of buildNumber, instead ${buildNumber as test}). What do i do wrong? i also want to have the files installed with ${project.version} ${buildNumber}.
thx for any help
markus
Not 100% sure I follow your question, but I had a problem getting a build number in my WAR manifest. The discussion here helped me out. I had to create a global property called build.version
<properties>
<build.version>${project.version}-r${buildNumber}</build.version>
</properties>
and use that instead of using ${buildNumber} directly. Hopefully that'll be some help with your problem.