changing maven site plugin source folder - maven

I need to change the maven site documentation source folder. I've check the plugin documentation and couldn't find this configuration.
Problem scenario:
I have a maven project with several child project, and one of this child is only a angular2 project.
On the angular project, the source folder has the pom.xml and several angular files, and one of the folder used by angular is 'src' (which is there the components, services, etc are stored).
I need to add maven site to this project, and it look the source files into 'src/site/*'. This works, but this 'site' folder is mixed with several ts files, and this looks messy, so I need to change the default folder for maven site plugin.
Is there any way to change it?

If you wish to change the source directory in which Maven looks for, although I would rather recommend to clean your directory, I think what's below should work:
<build>
....
<plugins>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.4</version>
<configuration>
<siteDirectory>my/site/dir</siteDirectory>
</configuration>
</plugin>
....
</plugins>
....
</build>

Related

maven-jar-plugin does not include .gitignore file

I try to package an application into a jar file with maven. Somehow all files except .gitignore files are added to the jar.
Why is this file skipped and how can I disable this?
Even if I try to include it like below the include is ignored and the jar file remains empty.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<includes>
<include>**/.gitignore</include>
</includes>
</configuration>
</plugin>
maven-jar-plugin version: 3.1.0
maven version: 3.5.2
I tried this with a src/main/resources/.gitignore and it worked with the default maven-jar-plugin:2.4, i.e. .gitignore was packaged into the JAR.
Then I used the maven-jar-plugin:3.1.0 you mention and it did not work, as you describe.
It turned out that it doesn't work from v2.5 onwards.
I have the same issue with a .metadata folder in the target/classes folder. The .metadata folder is not included in the jar archive.
For me, it is not working with maven-jar-plugin:2.4 and upper. With version 2.3 it is working.
I submitted this issue : https://issues.apache.org/jira/browse/MJAR-265
The first thing is using a jar file example projects is astonishing. I would never expect to have example projects within a .jar file. The intention of a jar files is something different. I would suggest to use something more appropriate like .zip or .tar.gz etc. (This can be achieved with the maven-assembly-plugin) This will prevent accidental not intended use.
Apart from the whole problem is based on the definition of resources which are usually copied from src/main/resources to the target/classes directory. This is done by the maven-resources-plugin.
The maven-resources-plugin plugin has some kind of configuration which excludes some files which are usually not copied which contains .gitignore. So this means just putting a .gitignore file into src/main/resources will not produce the expected result nor using <includes>..</includes> configuration will not help here as well.
This means you need to change the default configuration of maven-resources-plugin via pluginManagement section like the following:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<addDefaultExcludes>false</addDefaultExcludes>
</configuration>
</plugin>
Than the .gitignore file will be copied and should be packaged into the resulting jar file (Which I would not recommend to do.)

What is the best place for JavaDoc files in a Maven project using Tomcat?

I am regularly deploying a Maven project to a Tomcat server, using Travis CI. My project is a web app, so I have configured my pom.xml for building a WAR file, instead of a JAR:
...
<packaging>war</packaging>
...
With Maven, I can generate a directory containing all the JavaDoc files for my project; Maven puts them in the target/site/apidocs directory. But then, when I deploy my project, Travis doesn't perform any mvn site phase so I don't have my JavaDocs on the server.
Should I edit my pom.xml so that Maven puts the JavaDoc files somewhere in the src directory (instead of target) or is there a way to package the JavaDoc files together with the WAR file? I thought that I could create a docs/ directory inside src/main/webapp/. Specifically: is it "good practice" to generate my JavaDoc in src instead of target? if not, how can I have a WAR file containing my JavaDoc?
What would you suggest is the best thing to do?
I already know how to generate a standalone JAR containing my JavaDoc files (see here), but this is not what I'm looking for.
Use the site plugin https://maven.apache.org/plugins/maven-site-plugin/ and the javdoc plugin https://maven.apache.org/plugins/maven-javadoc-plugin/usage.html.
Add the following to your pom.xml
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links>
<link>http://commons.apache.org/lang/api</link>
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
<link>http://this-one-will-not-work</link>
</links>
</configuration>
</plugin>
</plugins>
</reporting>
then mvn site:site your documentation will be in target/site you can also deploy it.

Exclude hidden folders to generate archetype

I'm using the command:
mvn archetype:create-from-project -Darchetype.properties=./archetype.properties
I want exclude hidden dirs, for example .sonar, I try the follow options:
excludePatterns=**/*sonar/*
and
excludePatterns=**/.sonar/*
but not working form me, with non hidden dirs work well.
How can I exclude hidden directories?
There is a bug in version 2.4 of the Archetype Plugin in which certain files that match the exclude patterns are still included. I created ARCHETYPE-513 to track this and this bug has been fixed for version 3.0.0 of the plugin. Thus, make sure you use this version by specifying in your POM:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
To recap, the excludePatterns property should be present in the property file, configured with propertyFile or the -Darchetype.properties user property, that is used by the plugin. So the following archetype.properties property file:
excludePatterns=**/.sonar/**
used with mvn clean archetype:create-from-project -Darchetype.properties=archetype.properties will correctly exclude all folders named .sonar that are present in your project when the archetype is created.

How to avoid checking parent project in maven-site-plugin?

I have small maven project. I'm trying to add generating site by maven-site-plugin, but it doesn't work. When I'm building this project i get following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project server-wms-product: SiteToolException: The site descriptor cannot be resolved from the repository: ArtifactResolutionException: Unable to locate site descriptor: Could not transfer artifact [PARENT-PROJECT]:xml:site_en:1.0.141.1 from/to eclipse (http://maven.eclipse.org/nexus/content/repositories/testing/): Connection to http://maven.eclipse.org refused
My project is extension for other project, so in my pom.xml is set parent project which isn't mine and I can't add site configuration there.
So is there any chance to skip checking parent project's site in site generation?
My pom.xml looks like this:
<project>
<parent>
<artifactId>base-server-product</artifactId>
<groupId>XXXXXXXXXXXx</groupId>
<version>1.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<configuration>
<reportPlugins>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</project>
And of course i have site.xml file in src/site.
Configure attaching the site descriptor to the artifacts in the parent pom.
<project>
<artifactId>base-server-product</artifactId>
<groupId>XXXXXXXXXXXx</groupId>
<version>1.0</version>
...
<build>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<executions>
<execution>
<id>attach-descriptor</id>
<goals>
<goal>attach-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Core functionality has been separated from site generation in maven 3. You can find the reasons here. If you want to refer to the parent module's site from the submodule, you have to attach the site.xml to the deployed artifacts.
I have the exact same problem, and after much googling, came across this article which solved my problem:
http://amanica.blogspot.com/2010/08/archiva-gives-maven-site-plugin-invalid.html?m=1
Basically you want to add a basic site_en.xml to /src/site/ folder in your parent pom.xml.
For a reason I can't fathom, with me, it was enough to run maven in offline mode once.
I came across this question when working on an open source project I don't own where I wanted to submit an update to a site being generated in this manner. I wanted to test and view the change locally, but kept hitting this error.
User #Frischling alluded to this above (credit to them). It turns out what I wanted was not to edit any existing information or update any pom.xml files, but just build entirely in offline mode.
I was trying to run this command and it was failing with the error the original poster mentioned:
mvn site
To do this build offline instead, execute the following commands:
# Download the dependencies for the target
mvn dependency:go-offline site
# Build the target offline
mvn --offline site
Then the output got correctly generated to the target/site directory like I expected.
It's not ideal if you own the project or part of the project, but for a case like mine where I owned none of it, it was the perfect option.
The previous answers didn't work for me.
But Mark's one, here, solved the issue I had: https://stackoverflow.com/a/57429991/5056068
Etienne

Where should a custom Netbeans Platform conf. file be so that maven finds it?

Applications built on top of the NetBeans platform have a <myappdir>/etc/<myapp>.conf file determining, among other things, application JVM parameters. Historically, this file was a part of the NetBeans IDE installation (as far as I could tell), but starting with NB 6.9, custom files are now supported.
I am having trouble packaging a custom configuration file using Maven to build the application.
I imagine the app.conf property should have been set in the project's pom under project/build/pluginManagement/plugins like so:
<plugin>
...
<configuration>
<brandingToken>${brandingToken}</brandingToken>
<cluster>${brandingToken}</cluster>
<appConf>myapp.conf</appConf>
</configuration>
The maven module representing my application contained no prior source, so I created the src/main/nbm folder and placed myapp.conf in src/main/nbm. This isn't picked up by nbm-maven-plugin. and putting the conf file into src/main/resources doesn't make a difference.
So, can anyone explain how a NetBeans Platform application with a custom configuration file can be built using maven?
UPDATE:
With Tim's prod in the right direction, I found the answer documented on Geertjan's blog. The solution is to configure the nbm-maven-plugin like so in the application module pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<configuration>
<etcConfFile>src/main/resources/my.conf</etcConfFile>
</configuration>
</plugin>
</plugins>
</build>
BTW, if you need a second name with Geertjan, you're not really a NetBeans platform developer. ;)
Have a look at the documentation of the nbm:cluster-app plugin, specifically the part on the conf file.
As per my understanding that should allow you to replace the default one with a custom one that you create.

Resources