You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Brent Hale <br...@eventronix.com> on 2004/12/06 19:20:14 UTC

Re: refresh source file set - Solution

FWIW...I also (just barely) found and interesting thread from 1/8/2004 
entitled "Mutliple source directories in project.xml".  It talks about 
the possibility of a <generatedSourceDirectory> element to the POM.  I 
don't see that it ever made it in, but perhaps someone else knows better.

Thanks,
Brent


Brent Hale wrote:

> Well here's how I got around it if it helps anyone else.  I also think 
> this is a bug in how Maven behaves but you tell me.
>
> In my situation I am generating 300+ database object classes from a 
> prioritary DB schema to POJO (I put these in 
> ${basedir}/target/generated/src/java).  Of those, 80+ files have been 
> modified since their creation and are under revision control.  I put 
> those in my ${basedir}/src/java directory.  I wanted to auto-generate 
> the files, copy the modified files over the top of the generated ones 
> and compile.
>
> I couldn't get Maven to do what I expected.
>
> I had tried setting the <sourceDirectory> in project.xml to 
> ${basedir}/target/generated/src/java, but, after performing a "clean" 
> the directory is not there.  And when starting the normal maven 
> compile process it seems that Maven sets a flag saying "There are no 
> source files to compile" and it never seems to check again before the 
> compiling process even though there are now files in that directory.
>
> So to get around it I did the following:
>
> I kept the <sourceDirectory> in project.xml pointing at 
> ${basedir}/src/java so that Maven would think that there was source to 
> compile.  After auto-generating the files I did the following to add 
> the newly generated directory/files to the "maven.compile.src.set" 
> property so that it would compile the newly created files AND the 
> files that were copied over the top of each other.
>
>           <ant:path
>               id="generated.files.dir"
>               location="${basedir}/target/generated/src/java"/>
>
>           <maven:addPath
>               id="maven.compile.src.set"
>               refid="generated.files.dir"/>      
> At this point there would be a problem since there would be duplicate 
> file/package names under both directories.  So I created a preGoal and 
> postGoal to java:compile to the compilation process which moves all of 
> the original source code into a temporary directoy so that they won't 
> get compiled and then moves them back after the compilation step is 
> completed.
>   <preGoal
>        name="java:compile">
>              <echo message="Move the original set of source code out 
> of the way."/>
>        <move todir="${basedir}/src/java.org">
>            <fileset dir="${basedir}/src/java"/>
>        </move>
>     </preGoal>
>
>    <postGoal
>        name="java:compile">
>
>        <echo message="Move the original set of source code back."/>
>        <move todir="${basedir}/src/java">
>            <fileset dir="${basedir}/src/java.org"/>
>        </move>
>     </postGoal>
>
>          That seems to work.
> This seems like a bug in Maven.  I would assume that it should check 
> for source code to compile during the java:compile phase or at least 
> after a preGoal to java:compile.  Lots of things can happen along the 
> way that might affect the source list.
>
> Below is a response I received from the original poster of the 
> problem.  His comments also show the frustration of trying to do 
> this.  I however, could not resort to a separate batch file.
> ---------------------------------------------
>
> Here are two things that might work:
> - keep the generated-source directory in place
>    IIRC, it's not the missing files that troubles maven,
>    but the missing directory.  But I'm not sure about this...
>
> - Use a wrapper (that's what I did)
>    First generate the source files, then call maven.  I'm using a
>    "build.bat" that calls ant, which in turn generates the source
>    files and calls maven.
>       <target name="compile" description="compiles the source code"
>            depends="generate-source">
>      <antcall target="-maven">
>        <param name="goal" value="java:compile"/>
>      </antcall>
>    </target>
>
> It might be worth a try asking the maven developers for that refresh
> feature, though.
>
> Ron
>
>
>
>
> Brent Hale wrote:
>
>> Does anyone know of a solution for this problem?  This is quite an 
>> old post but I'm having the same issue and am trying to figure out 
>> how to handle this.
>>
>> Brent
>>
>>
>> Ronald Blaschke wrote:
>>
>>> Hi,
>>>
>>> I'd like to automatically generate some java source files and thought
>>> I could do it like this.
>>>
>>> - Specify a "generated" source directory, eg target/generated-java in
>>> project.xml
>>> - In maven.xml:
>>>  <preGoal name="java:compile">
>>>    <attainGoal name="generate-source"/>
>>>  </preGoal>
>>>
>>> whereas "generate-source" does
>>> - Copy plain java files from src/java to target/generated-java
>>> - Generate source files as needed into target/generated-java
>>>
>>> Unfortunately maven complains with
>>>    [echo] No java source files to compile.
>>>
>>> My question: How do I "refresh" the source file set maven uses?
>>>  <preGoal name="java:compile">
>>>    <attainGoal name="generate-source"/>
>>>    <attainGoal name="refresh-source-file-set"/> <!-- but how? -->
>>>  </preGoal>
>>>  
>>> Regards,
>>> Ronald
>>>  
>>>
>>
>

-- 
Brent Hale
Fishbowl Inventory
www.fishbowlinventory.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org