You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Dmitry Trunikov <dm...@zoral.com.ua> on 2012/07/03 16:55:25 UTC

reactor build && changes in module && recompilation of dependent modules

Hi All,

It seems that my question has an obvious answer. Unfortunately googling 
didn't give me a good one.

Prerequisites:

I have a classical multi-module project. The root POM declares two 
modules: 'api' and 'impl'.
These modules have references to the parent.
The module 'api' contains definition of an interface.
The module 'impl' has dependency on 'api' and a class which implements 
the interface.

Issue:

In the top directory I run a reactor build:

[First build]
$ mvn clean compile

The build finished with success.
Then I made changes in the interface declaration in the module 'api' 
(added a new method) and run build again:

[Second build]
$ mvn compile

The build finished with success again. It is strange because I expected 
that build finished with failure because class in the module 'impl' had 
no implementation of the method just added to the interface.
When I run build with command:

[Third build]
$ mvn clean compile

It finished, as I expected, with failure.

Question:

Why Maven didn't complain on second build?


Thanks for your help,

Dmitry

Re: reactor build && changes in module && recompilation of dependent modules

Posted by Dmitry Trunikov <dm...@zoral.com.ua>.
Hi Wayne,

The app version is '1.0-SNAPSHOT'.
The Maven is:

$ mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 19:31:09+0200)
Maven home: /opt/maven
Java version: 1.6.0_29, vendor: Sun Microsystems Inc.
Java home: /opt/jdk1.6.0_29/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-25-generic", arch: "amd64", family: "unix"

Below are the POMs which I use to reproduce the issue.
Directory structure:

pom.xml              [root pom, the builds were run in this dir]
|
+-api                   [module of an interface]
|   |
|   +pom.xml
|
+-impl                 [module of an implementation]
     |
     +pom.xml


The root POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">

     <modelVersion>4.0.0</modelVersion>

     <groupId>a.b.c</groupId>
     <artifactId>foo</artifactId>
     <packaging>pom</packaging>
     <version>1.0-SNAPSHOT</version>

     <modules>
         <module>api</module>
         <module>impl</module>
     </modules>

     <build>
         <pluginManagement>
             <plugins>
                 <plugin>
<artifactId>maven-clean-plugin</artifactId>
                     <version>2.4.1</version>
                 </plugin>
                 <plugin>
<artifactId>maven-resources-plugin</artifactId>
                     <version>2.5</version>
                 </plugin>
                 <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
                     <version>2.4</version>
                     <configuration>
                         <source>1.6</source>
                         <target>1.6</target>
                     </configuration>
                 </plugin>
             </plugins>
         </pluginManagement>
     </build>
</project>


The POM for 'api' module:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">

     <modelVersion>4.0.0</modelVersion>

     <parent>
         <groupId>a.b.c</groupId>
         <artifactId>foo</artifactId>
         <version>1.0-SNAPSHOT</version>
         <relativePath>..</relativePath>
     </parent>

     <artifactId>foo-api</artifactId>
     <version>1.0-SNAPSHOT</version>
     <packaging>jar</packaging>

     <build>
         <finalName>foo-api</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
     </build>

</project>

The POM for 'impl' module:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">

     <modelVersion>4.0.0</modelVersion>

     <parent>
         <groupId>a.b.c</groupId>
         <artifactId>foo</artifactId>
         <version>1.0-SNAPSHOT</version>
         <relativePath>..</relativePath>
     </parent>

     <groupId>a.b.c</groupId>
     <artifactId>foo-impl</artifactId>
     <version>1.0-SNAPSHOT</version>
     <packaging>jar</packaging>

     <dependencies>
         <dependency>
             <groupId>a.b.c</groupId>
             <artifactId>foo-api</artifactId>
             <version>1.0-SNAPSHOT</version>
         </dependency>
     </dependencies>

     <build>
         <finalName>foo-impl</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
     </build>

</project>


Thanks for your help,

Dmitry



On 07/04/2012 12:15 AM, Wayne Fay wrote:
>> Question:
>>
>> Why Maven didn't complain on second build?
> What are the versions of the various projects in your build?
>
> Wayne
>


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


Re: reactor build && changes in module && recompilation of dependent modules

Posted by Wayne Fay <wa...@gmail.com>.
> Question:
>
> Why Maven didn't complain on second build?

What are the versions of the various projects in your build?

Wayne

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


Re: reactor build && changes in module && recompilation of dependent modules

Posted by Stephen Connolly <st...@gmail.com>.
Keep in mind that the reactor in general resolves the jar within the
multi-module project... so you don't know which source files changed as
easily and therefore you don't know which .class files to remove

If you run with -DskipTests most builds are very fast anyway (hey I
regularly rebuild all of Jenkins clean every day) and any decent unix guy
worth their crusties should be able to fork maven in the background to
build for them ;-)

On 4 July 2012 15:30, Dmitry Trunikov <dm...@zoral.com.ua> wrote:

>
>  The way I do this is to use my IDE's dependency analysis to have my IDE
> do a "Make" (which rebuilds all the downstream changes)... then before I
> commit I will do a "mvn clean verify" to make sure that my changes are good
>
>
> Yes my IDE does the analysis too.
> The problem is in my colleague.
> He is unix geek and orthodox and use Emacs as java IDE. At the start of
> the project we had a long discussion what use as build tool.
> He insisted on Ant because he knew exactly how it works and can easily
> adjust build process.
> I proposed to use Maven as it has perfect support of multi-module projects
> (at least I thought so at that time).
> I frustrated a lot because in my opinion recompilation of dependent
> modules when dependency was changed is a main goal of any matured build
> tool.
> And I was convinced that Maven reactor mechanism does it perfectly.
> Actually I can't believe in absence of such functionality in Maven.
>

Re: reactor build && changes in module && recompilation of dependent modules

Posted by Dmitry Trunikov <dm...@zoral.com.ua>.
> The way I do this is to use my IDE's dependency analysis to have my 
> IDE do a "Make" (which rebuilds all the downstream changes)... then 
> before I commit I will do a "mvn clean verify" to make sure that my 
> changes are good
>

Yes my IDE does the analysis too.
The problem is in my colleague.
He is unix geek and orthodox and use Emacs as java IDE. At the start of 
the project we had a long discussion what use as build tool.
He insisted on Ant because he knew exactly how it works and can easily 
adjust build process.
I proposed to use Maven as it has perfect support of multi-module 
projects (at least I thought so at that time).
I frustrated a lot because in my opinion recompilation of dependent 
modules when dependency was changed is a main goal of any matured build 
tool.
And I was convinced that Maven reactor mechanism does it perfectly.
Actually I can't believe in absence of such functionality in Maven.

Re: reactor build && changes in module && recompilation of dependent modules

Posted by Stephen Connolly <st...@gmail.com>.
On 4 July 2012 09:46, Dmitry Trunikov <dm...@zoral.com.ua> wrote:

>
>  javac will only recompile classes that have changed. it does not do
>> dependency analysis, so a breaking change will only cause a compile failure
>> until you do clean
>>
>>
> Thank you for clarification.
> Is there any way (except explicit 'clean') to turn on dependency analysis
> during compilation.
> The project consists of tens of modules so approach with 'clean' is not
> good enough because full re-biuld requires relative significant amount of
> time.
>
>
The way I do this is to use my IDE's dependency analysis to have my IDE do
a "Make" (which rebuilds all the downstream changes)... then before I
commit I will do a "mvn clean verify" to make sure that my changes are good


>
> Thanks for your help,
> Dmitry
>

Re: reactor build && changes in module && recompilation of dependent modules

Posted by Dmitry Trunikov <dm...@zoral.com.ua>.
> javac will only recompile classes that have changed. it does not do 
> dependency analysis, so a breaking change will only cause a compile 
> failure until you do clean
>

Thank you for clarification.
Is there any way (except explicit 'clean') to turn on dependency 
analysis during compilation.
The project consists of tens of modules so approach with 'clean' is not 
good enough because full re-biuld requires relative significant amount 
of time.

Thanks for your help,
Dmitry

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


Re: reactor build && changes in module && recompilation of dependent modules

Posted by Stephen Connolly <st...@gmail.com>.
On 3 July 2012 15:55, Dmitry Trunikov <dm...@zoral.com.ua> wrote:

> Hi All,
>
> It seems that my question has an obvious answer. Unfortunately googling
> didn't give me a good one.
>
> Prerequisites:
>
> I have a classical multi-module project. The root POM declares two
> modules: 'api' and 'impl'.
> These modules have references to the parent.
> The module 'api' contains definition of an interface.
> The module 'impl' has dependency on 'api' and a class which implements the
> interface.
>
> Issue:
>
> In the top directory I run a reactor build:
>
> [First build]
> $ mvn clean compile
>
> The build finished with success.
> Then I made changes in the interface declaration in the module 'api'
> (added a new method) and run build again:
>
> [Second build]
> $ mvn compile
>
>
javac will only recompile classes that have changed. it does not do
dependency analysis, so a breaking change will only cause a compile failure
until you do clean


> The build finished with success again. It is strange because I expected
> that build finished with failure because class in the module 'impl' had no
> implementation of the method just added to the interface.
> When I run build with command:
>
> [Third build]
> $ mvn clean compile
>
> It finished, as I expected, with failure.
>
> Question:
>
> Why Maven didn't complain on second build?
>
>
> Thanks for your help,
>
> Dmitry
>