Page 1 of 2 12 LastLast
Results 1 to 20 of 28
  1. #1
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Several Compilations in one POM.xml

    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.

  2. #2
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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.

  3. #3
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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?

  4. #4
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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.

  5. #5
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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.

  6. #6
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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!

  7. #7
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    just show up your poms.

  8. #8
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    __________ 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>

  9. #9
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    [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.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Several Compilations in one POM.xml

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    Quote Originally Posted by noctarius View Post
    just show up your poms.
    Hi noctarius!
    So what may you tell about my poms?

  12. #12
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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.

  13. #13
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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,

  14. #14
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    and project2 finalizes with success?

  15. #15
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    yes, sure.

  16. #16
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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.

  17. #17
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    crossusing goals?

  18. #18
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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..

  19. #19
    noctarius is offline Member
    Join Date
    Jun 2012
    Location
    Remscheid, Germany
    Posts
    61
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    You have a cleanly defined lifecycle which is executed in order, there's nothing like depending goals / phases.

  20. #20
    AlexSerov is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default Re: Several Compilations in one POM.xml

    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.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •