I need to compile some Java classes from one directory and later after some other step to compile classes from a different directory. How my POM file should be organized? So far it looks like Maven does not like it.:frusty:
Printable View
I need to compile some Java classes from one directory and later after some other step to compile classes from a different directory. How my POM file should be organized? So far it looks like Maven does not like it.:frusty:
You can add more than one source directory (build-helper-plugin) and compile all that sourcefiles at once. The other (typical) possibility is to make multiple submodules and compile them all on themselfs but to use dependencies.
I may not compile them all at once - the intermediate step examines the class files of the first translation (using reflection) and only then generates Java files for the supposed second translation. Is the other way you propose about multi-module/aggregation? I will appreciate if you give me a top-level example of POM structure for this case. Both at step 1 and step 3 maven-compiler-plugin is supposed to be executed. Step 2 is my own plugin (let it be my-own-plugin). How dependencies of steps 1-2-3 should be depicted so that maven does not toss the order?
You use one parent module and 2 submodules. First you compile the module containing the classes you want to inspect later on. The second module has the first as a dependency so that maven know in which order to build the modules. In the second module you examine classes and generate the source in the generate-sources goal and compile them using the standard compile phase. The build-helper-plugin will be used to tell maven the sourcepath of the generated sources.
I think that is doable but seems to require to change all the current directory structure. It is regrettable because it would impact existing ant files. It seems that one small feature currently absent in maven could help - the pom files would better have been permitted other names than hardcore pom.xml and accordingly the <module> element would be permitted to contain pom files names besides directories only.
Good news - I tried setting three poms in one and the same directory, so name of pom file works:
In my pom.xml:
<modules>
<module>pom1.xml</module>
<module>pom2.xml</module>
</modules>
And when I run mvn install and I see that pom1.xml is executed. But pom2.xml - not!
just show up your poms.
__________ pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.mojo</groupId>
<artifactId>my-parent</artifactId>
<version>2.0</version>
<packaging>pom</packaging>
<modules>
<module>pom1.xml</module>
<module>pom2.xml</module>
<module>pom3.xml</module>
</modules>
</project>
__________ pom1.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" ... >
<modelVersion>4.0.0</modelVersion>
<groupId>com.hybridjava</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>project1</artifactId>
<build>
<sourceDirectory>.</sourceDirectory>
<outputDirectory>classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<includes>
<include>pojos\com\HybridJava\Sample\*.java</include>
<include>pages\com\HybridJava\Sample\*_PS.java</include>
<include>widgets\com\HybridJava\Sample\*_WS.java </include>
<include>widgets\com\HybridJava\Lib\*_WS.java</include>
</includes>
<compilerArguments>
<classpath>..\lib\HybridJava.jar;..\lib\HybridJava _rt.jar;..\lib\servlet-2_3-fcs-classfiles.jar;classes</classpath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>org.apache.maven.plugins</id>
<url>http://maven.apache.org/plugins</url>
</pluginRepository>
</pluginRepositories>
</project>
__________ pom2.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" ... >
<modelVersion>4.0.0</modelVersion>
<groupId>com.hybridjava</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>project2</artifactId>
<build>
<plugins>
<plugin>
<groupId>com.hybridserverpages</groupId>
<artifactId>hybridjava-compiler-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.hybridserverpages</groupId>
<artifactId>hybridjava-compiler-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.hybridjava</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>project1</artifactId>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>com.hybridjava</id>
<url>http://hybridjava.com/maven2</url>
</pluginRepository>
<pluginRepository>
<id>org.apache.maven.plugins</id>
<url>http://maven.apache.org/plugins</url>
</pluginRepository>
</pluginRepositories>
</project>
_________ pom3.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" ... >
<modelVersion>4.0.0</modelVersion>
<groupId>com.hybridjava</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>project3</artifactId>
<build>
<sourceDirectory>.</sourceDirectory>
<outputDirectory>classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>install</phase>
</execution>
</executions>
<configuration>
<includes>
<include>gen\com\HybridJava\Sample\*_P.java</include>
</includes>
<compilerArguments>
<classpath>..\lib\HybridJava.jar;..\lib\HybridJava _rt.jar;..\lib\servlet-2_3-fcs-classfiles.jar;classes</classpath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.hybridjava</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>project2</artifactId>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>org.apache.maven.plugins</id>
<url>http://maven.apache.org/plugins</url>
</pluginRepository>
</pluginRepositories>
</project>
[INFO] Reactor Build Order:
[INFO]
[INFO] project1
[INFO] project2
[INFO] project3
[INFO] my-parent
Then project1 and project2 work but project3 - as if it does not exist.
Please show the log of the build process (sorry missed the thread). At least in pom3.xml change the compilers phase to compile... you cannot compile while installing the artifacts.
changed the phase to "compile" but it did not help.
C:\Users\admin\Desktop\Root\MavenTest\Test>cmd /k mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] project1
[INFO] project2
[INFO] project3
[INFO] my-parent
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project1 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ project1 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\admin\Desktop\Root\MavenTest\Test\src\mai n\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5:compile (default-compile) @ project1 ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 17 source files to C:\Users\admin\Desktop\Root\MavenTest\Test\classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ project1 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\admin\Desktop\Root\MavenTest\Test\src\tes t\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5:testCompile (default-testCompile) @ project1 ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ project1 ---
[INFO] No tests to run.
[INFO] Surefire report directory: C:\Users\admin\Desktop\Root\MavenTest\Test\target\ surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ project1 ---
[INFO] Building jar: C:\Users\admin\Desktop\Root\MavenTest\Test\target\ project1-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ project1 ---
[INFO] Installing C:\Users\admin\Desktop\Root\MavenTest\Test\target\ project1-0.0.1-SNAPSHOT.jar to C:\Users\admin\.m2\repository\com\hybridjava\proje ct1\0.0.1-SNAPSHOT\project1-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\admin\Desktop\Root\MavenTest\Test\pom1.xm l to C:\Users\admin\.m2\repository\com\hybridjava\proje ct1\0.0.1-SNAPSHOT\project1-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ project2 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\admin\Desktop\Root\MavenTest\Test\src\mai n\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ project2 ---
[INFO] No sources to compile
[INFO]
[INFO] --- hybridjava-compiler-plugin:1.0-SNAPSHOT:sayhi (default) @ project2 ---
[INFO] Hello HybridJava compiler!
... ... ... Then only outpot from pom2 follows,
and project2 finalizes with success?
yes, sure.
In general I do not (now) quite well understand how the maven goals may be used otherwise than from a command line. I would (yesterday) expect that using goals we may force the order of executions. Now can not find any examples of cross-using goals.
crossusing goals?
I recall that in classic make (ant) nodes depend on other nodes. Make defines the order of build. I though before that goals in maven serve to depict such dependencies and same way may control the order of steps..
You have a cleanly defined lifecycle which is executed in order, there's nothing like depending goals / phases.
Clearly defined as non-flexible. If I want two compilations one after another then I am advised to use two <execution> elements. Compilations will happen one after another. So far I do not see how to push some additional step of my own between those two compilations.