Property Replacement in Maven Site Content - maven

I'm generating maven site content using the site plugin. I want to have a little table that shows my maven group id, artifact id, parent info, etc on the module. I don't see a plugin for it, so I was going to use the APT format and create a content page with a table for it. The documentation says I can use property replacement in the site descriptor via ${project.name} etc. This fails when i use it in both the descriptor and in my index.apt file. Has anybody seen this done or know how to do it?

The mvn site command generates a Project Summary page which has this information on it. Does that work for you?
For example, when I execute mvn site, get an output here target/site/project-summary.html where the page has a section like so:
Build Information
Field Value
GroupId com.a.b
ArtifactId myapp
Version 1.01.13-SNAPSHOT
Type jar

If you want to create pages which use placeholder like ${project.version} etc. you need to use index.apt.vm (velocity files) wher the replacement works. But for the information you have asked the solution which has been described (project-summary.html) is the right way cause it's automatically generated.

Related

prompt user while creating maven project using archetype

We have created maven archetype for users to generate project. Now we want a certain archetype property to be set using the user input. Can somebody point out a way by which we can prompt the user for input during project generation and use the input to set the property?
Make use of a property file, visit http://maven.apache.org/archetype/maven-archetype-plugin/examples/create-with-property-file.html to see how this works.

Load different stylesheets when packaging a war file with Grails

I want to package a Grails application for different brands. While generating a war file, I want to pass some custom parameter that refers to a certain brand and styles the application by loading the stylesheet for the brand.
I read online and one approach I found was with maven. I tried working with maven but I am stuck while initially compiling the application. The error is
Failed to execute goal org.grails:grails-maven-plugin:2.2.1:maven-compile
(default-maven-compile) on project foreAction: Forked Grails VM exited with error.
I am stuck as to what approach to take now. I searched for the above error and tried different solutions but nothing seems to work.
If there is a different way without using Maven I am willing to give it a shot.
You could always hook into the events using scripts/_Events.groovy and replace the appropraite CSS/assets. The documentation explains how to hook into build events.
Your code inside scripts/_Events.groovy might look something like this:
// This is called after the staging dir is prepared but before the war is packaged.
eventCreateWarStart = { name, stagingDir ->
// place your code here that copies your resources to the appropriate location in the staging directory.
Ant.copy(
file: System.getProperty('somePassedInFile'),
toFile: "${stagingDir}/assets/stylesheets/whatever.css",
overwrite: true
)
}
Then you can pass in the value of the source file from grails prod war like this:
grails prod war -DsomePassedInFile=/path/to/file.css
Hope this helps at least give you an idea of how you can accomplish this. (All written off the top of my head so beware of typos etc.)

specify custom location of maven security-settings.xml file?

with maven you can easily specify settings.xml location, e.g:
mvn -s custom/dir/settings.xml package
Is there a similiar way to specify custom security-settings.xml?
The reasoning behind this is simple: to easily distribute it via a local repository. Now, security is NOT a concern - it's all on the intranet.
This was requested as MNG-4853. Although not implemented directly, a workaround is suggested:
I've verified that -Dsettings.security=path/to/security-settings.xml works
As detailed in the announcement blog post, you can also use the master password relocation feature. Write an ~/.m2/security-settings.xml file with a redirection in it:
<settingsSecurity>
<relocation>/Volumes/mySecureUsb/secret/settings-security.xml</relocation>
</settingsSecurity>

Maven plugin: copy a file content into another file

I am looking for the appropriate plugin to copy a file content into another file.
My resource.xml has content like this:
<class>my.path.ResourceA</class>
<class>my.path.ResourceB</class>
<class>my.path.ResourceC</class>
and must be copied to destination.xml at the place of ${content}:
<aaa>some info</aaa>
${content}
What the proper maven plugin to do that task, please?
Thank you in advance.
Nic
In general with Maven, you must first thinkg WHAT you want to do. Might seem weird at first sight, but as Maven is an opinionated build tool, it will generally be not simple to do weird/workaround things ;-).
Here, you would need two things:
load that file into a "content" property (before resource filtering starts by binding to an early phase, obviously, see the next point)
just activate resource filtering and be done
Unfortunately, there's no well-known/standard plugin for the (1) able to load a file inside a property.
A possible way, before rewriting it through a dedicated plugin or so, would be by using antrun-maven-plugin (through LoadFile task?) or gmaven plugin to load that file into a property (during the initialize phase, for example, so that it happens before process-resources, see the documentation about lifecycle.)
Then, for (2), you simply have to activate filtering (see the standard documentation of the maven-resources-plugin).
The answer from Baptiste does not work with the antrun plugin, as the properties from the LoadFile task are Ant properties are not accessible in Maven for filtering.
Instead, one can use the readfiles-maven-plugin, which you can find here: https://github.com/chonton/readfiles-maven-plugin

Placeholder substitution in a Maven APT page

I am working on Maven site documentation for some related projects, and I want to create a hyperlink from one site's documentation to another sites documentation. The wrinkle is that the URL for the link target depends on a Maven property.
I tried this:
{{{http://example.com/site/project-${some-prop}/some.html}the documentation}}
but the ${some-prop} placeholder doesn't get replaced, and the APT processor then gets
confused by the first '}'. Escaping the { and } characters (e.g. $\{some-prop\} ) doesn't help, and the following doesn't work either:
{{http://example.com/site/project-${some-prop}/some.html}}
Is there some other way that I can accomplish this task? For example, is there a way to define a Doxia macro that could be used to substitute a URL that had the placeholder expanded?
Are you using version 2.0-beta-6 or later of the site plugin? Also, does your apt filename ends with a .vm extension (as described in the filtering section of Creating Content?

Resources