Generate javadoc for test classes of Maven project in Netbeans - java

I think that the title is pretty self explanatory, how can I achieve that? By default Maven's javadoc plugin generates documentation only for "normal" classes.

You can set additional source paths for the maven-javadoc-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<sourcepath>${basedir}/src/main/java;${basedir}/src/test/java</sourcepath>
</configuration>
</plugin>
You may also want to tweak other javadoc:javadoc goal settings. You get set the complete list of options at its official site.

I've managed to solve my problem. To generate javadoc of test packages you have to go to properties of Maven project->Actions->Generate Javadoc and there add the goal: javadoc:test-javadoc.

Related

exclude src/main/java from compiling with maven-compiler-plugin

Is anybody known how to remove a Source roots from maven-compiler-plugin ?
[DEBUG] Source roots:
[DEBUG] C:\Workspace\Dev01\Internet_Login\src\main\java
[DEBUG] C:\Workspace\Dev01\Internet_Login\target\generated-sources\delombok
Because I generate source with lombok-maven-plugin from C:\Workspace\Dev01\Internet_Login\src\main\java but the maven-compiler-plugin use both Source roots and i get a compilation error.
After compiling, I use Aspectj so I need to do that this way, 'cause Lombok and Aspectj are "incompatible".
Is anybody got a solution.
EDIT :
I've got a solution. Just define the sourceDirectory in build and the compiler gonna use this directory.
<build>
<sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory>
...
</build>
Thx
did you try with excludes ?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>src/main/java/</exclude>
</excludes>
</configuration>
</plugin>
As Chrylis suggested, you ought to place any classes with Lombok annotations into src/main/lombok when using that plugin. This is clearly documented on its usage page.
There is also a sample project where you can see how plain Java classes without Lombok annotations are placed in src/main/java and the Lombok targets in src/main/lombok.
Just follow the instructions and you should be fine with regard to Maven Compiler plugin. As for AspectJ, it depends on how you want to weave your aspects (compile time, binary weaving, load time) and whether the aspects reside in the same or another module.

Generate Javadoc in Netbeans is disabled

I been looking around for hours and can't seem to find a solution to my problem. I am using Netbeans 8 and I would like to generate a Javadoc. I have formatted my comments to match Javadoc format. But the action menu (generate Javadoc) is disabled to any of the project.
How can I enable it? My project can be seen here: https://github.com/Daytron/SimpleDialogFX
I see that you are using Maven for your project. NetBeans' support for Maven is best-in-class since you almost never need to add anything to your Maven project in order for NetBeans to load it properly. To enable Javadoc during your build, simply add the following code to the <plugins> element within your <build> element.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Note: Since generating Javadoc may take a bit of time and those outputs are not necessary for debugging, I recommend only enabling the Javadoc output for a final build. However, the simplest path is certainly to just enable it all the time, which is what I've shown above.
Netbeans 8 needs to be restarted sometimes to show the Generate Javadoc.

Best way to set alternate JavaDoc location for all modules?

I'd like to set an alternate JavaDoc location for all my modules in a multi-module maven project. Unfortunately, I have to rely on relative paths, or else use maven properties like ${basedir}, since this is a team project on subversion, and no absolute path will be the same for all of us.
What is the best way to do this? If I have a project structure
parent
sub1
sub2
sub3
docs
And I want to place the API in sub3/docs, then how can I point all my modules to output HTML files in sub3/docs, when the parent module will recognize a different path to it than the submodules?
Thanks in advance.
You want to pollute your project build as little as possible, especially with repeated build tweaks. Instead, you're better off creating a separate build process that assembles the javadoc output from its standard location in all projects and publishes it somewhere desirable.
Add the following to the parent pom and make sure the child pom does not define their own javadoc plugin.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<outputDirectory>${project.parent.basedir}/sub3</outputDirectory>
<reportOutputDirectory>${project.parent.basedir}/sub3</reportOutputDirectory>
<destDir>docs</destDir>
</configuration>
</plugin>
</plugins>
</build>

Disabling Log4J logs during maven test phase

Trace and debug logs can be helpful while doing development in the IDE, but during the build I find those lines quite disturbing, and obfuscating the report printed out by maven or other build tools.
It would be nice to have log4j honoring a system property like -Dlog4j.rootLogger=OFF1 to use with maven or something which doesn't require changes on the project files.
I know I can specify the -Dlog4j.configuration=alternateconfig.props 2 but I'm asking here to find out if somebody found a smarter way to disable logging during the build process with minimal manual intervention. I.e. some java class detecting maven as caller that disables log4j, or other smart solutions.
Any hint?
Notes:
[1]: already tried, and it doesnt work.
[2]: that's pretty good, but it doesn't seem to work well with maven (maybe surefire skips it)
As explained by #artbristol (comment on the question) this can be configured in surefire.
It can be done in this way in the pom.xml:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<forkMode>always</forkMode>
<systemPropertyVariables>
<log4j.configuration>file:${basedir}/etc/log4j-silent.properties</log4j.configuration>
</systemPropertyVariables>
</configuration>
</plugin>
Then, having the file ${basedir}/etc/log4j-silent.properties with following settings does the trick:
log4j.rootLogger=OFF
The log4j gets completely disabled during test runs in maven, and everything works normally in the IDE.
A better solution would be not to have the additional configuration file; but can't find it so far.
Specify a test log4j configuration file with no appender.
For example if you have a log4j.properties in src/main/resources, then copy it to src/test/resouces and either remove the appender or set the log level to fatal.
Based on the previous answers, I use:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<forkMode>always</forkMode>
<argLine>-Dlog4j.configuration=</argLine>
</configuration>
</plugin>
The Maven output shows a warning about log4j not being initialized, but other than that it seems to work.

Preprocessing source code as a part of a maven build

I have a lot of Java source code that requires custom pre-processing. I'd like rid of it but that's not feasible right now so I'm stuck with it. Given that I have an unfortunate problem that shouldn't have existed in the first place, how do I solve it using maven?
(For the full story, I'm replacing a python-based build system with a maven one, so one improvement at a time please. Fixing the non-standard source code is harder, and will come later.)
Is it possible using any existing Maven plugins to actually alter the source files during compile time? (Obviously leaving the original, unprocessed code alone)
To be clear, by preprocessing I mean preprocessing in the same sense as antenna or a C compiler would preprocess the code, and by custom I mean that it's completely proprietary and looks nothing at all like C or antenna preprocessing.
There is a Java preprocessor with support of MAVEN: java-comment-preprocessor
This is something that is very doable and I've done something very similar in the past.
An example from a project of mine, where I used the antrun plug-in to execute an external program to process sources:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>process-sources</id>
<phase>process-sources</phase>
<configuration>
<tasks>
<!-- Put the code to run the program here -->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note the tag where I indicate the phase where this is run. Documentation for the lifecycles in Maven is here. Another option is to actually write your own Maven plug-in that does this. It's a little more complex, but is also doable. You will still configure it similarly to what I have documented here.
Maven plugins can hook into the build process at pre-compile time yes, as for whether or not any existing ones will help I have no idea.
I wrote a maven plugin a couple of years ago as part of a university project though, and while the documentation was a bit lacking at the time, it wasn't too complicated. So you may look into rolling your own, there should be plenty of open source projects you can rip ideas or code from (ours was BSD-licenced for instance...)

Categories

Resources