raydac/java-comment-preprocessor

generate-sources vs preprocess-sources vs maven-source-plugin

vlsi opened this issue · 11 comments

vlsi commented

When using maven-source-plugin, it forcefully executes generate-sources phase.
That causes:

  1. reprocessing of already processed sources
  2. failures if certain non-existent folders are present in "project source directories". For instance, maven-compiler-plugin seems to add /generated-sources/annotations folder to "project source directories" yet it might never be created.

While those might be bugs related to sources & compiler plugins, it will take a while for them to be fixed & released.

Am I doing something wrong? Does it make sense to elaborate JCP readme on the subject?

I switched to binding JCP to preprocess-sources to workaround maven-source-plugin.

could you make small maven based test project to reproduce the issue?
as I understand maven-source-plugin enforces generation phase to be sure that there will be sources which were presented during compilation because something could remove or change them
p.s.
found some resource http://blog.peterlynch.ca/2010/05/maven-how-to-prevent-generate-sources.html

made experiments with source plugin and started wiki page https://github.com/raydac/java-comment-preprocessor/wiki/MavenSourcePluginUsage

vlsi commented

Ah, sorry for being a bit slow. Do you still need a reproducer?

It looks like jar-no-fork seems to be the proper solution

looks like that it is a feature and not a bug, so if you are ok with jar-no-fork then we could close the issue

vlsi commented

Well, jar-no-fork produces preprocessed sources, so it solves the problem.

Do you mind including a hint on using jar-no-fork style of maven-source-plugin near sample of maven usage of JCP?

in my experiments jar-no-fork produces NON-PREPROCESSED sources, i.e. sources containing preprocessor directives, and just jar produces sources from preprocessing result folder
I think it will be enough to place link to the wiki page near the example of maven usage

vlsi commented

in my experiments jar-no-fork produces NON-PREPROCESSED sources,

Did you just say mvn clean package results in non-preprocessed source jar?

I tried mvn clean install and mvn clean package on a test project and in both cases sources.jar contain non-preprocessed sources with non-processed directives if I start jar-no-fork

if you have more complex case then would be good to make small test project reproducing the case to take a look how it works

vlsi commented

Here it is: https://github.com/vlsi/jcptest
I'm using java 8, maven 3, and it generates processed source jars (as expected :) ).

made experiments and figured out difference, IT DEPENDS ON ORDER OF PLUGINS in pom.xml, in my code I have preprocessor plugin described after maven-source-plugin and in your code it is on the first place and it makes difference in behaviour, if I place preprocessor in my code also to the first place then I get preprocessed sources in jar-no-fork!