Topics

Maven recompiles every time, even when code has not been changed


danielb987
 

I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.

If I run:

mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

and when it's done, run the same command again without changing anything:

mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.

I have tried "ant realclean" but it makes no difference.

Any idea of what is wrong?

Daniel


Randall Wood <rhwood@...>
 

Some .java source has no corresponding .class file after compilation.

Randall

On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:

I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.

If I run:

mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

and when it's done, run the same command again without changing anything:

mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.

I have tried "ant realclean" but it makes no difference.

Any idea of what is wrong?

Daniel



danielb987
 

I have this problem with JMRI master.

Is there a way to see which java files that don't have any class file? And how do I fix it?

It would be great if a check that ensures that every java file has a class file is added to CI so that a developer would be notified about it before a PR is merged into master.

Daniel

2020-07-10 19:27 skrev Randall Wood via groups.io:

Some .java source has no corresponding .class file after compilation.
Randall
On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:
I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.
If I run:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
and when it's done, run the same command again without changing anything:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.
I have tried "ant realclean" but it makes no difference.
Any idea of what is wrong?
Daniel


Randall Wood <rhwood@...>
 

.class files are the result of compiling the project and are not checked into code. It is not a compilation error that a .java file does not result in a .class file (nor is it a compilation error that a .java file compiles multiple .class files). It does however, make it really difficult for a build tool to determine that sources are compiled and current (especially since we also derive .java sources to compile from other non-.java sources).

How it gets fixed depends entirely on what the source is supposed to be.

Randall

On Jul 10, 2020, at 13:44, danielb987 <db123@...> wrote:

I have this problem with JMRI master.

Is there a way to see which java files that don't have any class file? And how do I fix it?

It would be great if a check that ensures that every java file has a class file is added to CI so that a developer would be notified about it before a PR is merged into master.

Daniel

2020-07-10 19:27 skrev Randall Wood via groups.io:
Some .java source has no corresponding .class file after compilation.
Randall
On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:
I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.
If I run:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
and when it's done, run the same command again without changing anything:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.
I have tried "ant realclean" but it makes no difference.
Any idea of what is wrong?
Daniel


Bob Jacobsen
 

Some of the package-info,java classes don’t generate class files.

java/src/apps/gui3/tabbedpreferences/package-info.java and java/src/apps/plaf/macosx/package-info.java do

java/src/apps/jmrit/package-info.java doesn’t.

The Ant compile step uses this

<compilerarg value="-Xpkginfo:always"/> <!-- compile all package-info.java to avoid empty-file warnings -->

and generates .class files for those.

One more data point:: for me, with JDK11,

ant realclean
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

The first maven run redid the source generation, then recompiled 4837 and 4353 files. The second did not regenerate source, and compiled the same number of files.

ant realclean
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
ant tests
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

Here, the ant line reduces the generation, compiles that, and then compiles 1 src and 3 test files. The second maven run still copies resources (two steps) but does _not_ recompile anything,

It could be those couple of recompiles, but it also could be the generated code. And compiles that as a separate step. When run after realclean, the three compile steps do 134, 4703 (which sum to 4837) and 4353 files.

As a test, I tried

ant realclean
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
ant jjtree javacc compile-generated-source
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest

When using Ant only, that ant line will just copy one file in the update-template-code step. This sequence _does_ do a maven recompile. So it seems whatever Ant is doing in the compile (src and/or test) is what’s making maven happy.

Running just “ant compile” after the above (but in the interest of time, I didn’t start at realclean) skips the maven recompile.

A look at file timestamps in target/classes seems to indicate that the one file that “ant compile” is persistently redoing when doing multiple “ant compiles” in sequence is from the update-template-code step: target/classes/jmri/Version.properties

Looking back at
ant realclean
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
ant compile

The single file compiled seems to have been java/src/apps/jmrit/package-info.java

Your mileage may vary. I hope there are some hints here that the maven users can use to fix the recompile.

Bob

On Jul 10, 2020, at 11:12 AM, Randall Wood via groups.io <rhwood=mac.com@groups.io> wrote:

.class files are the result of compiling the project and are not checked into code. It is not a compilation error that a .java file does not result in a .class file (nor is it a compilation error that a .java file compiles multiple .class files). It does however, make it really difficult for a build tool to determine that sources are compiled and current (especially since we also derive .java sources to compile from other non-.java sources).

How it gets fixed depends entirely on what the source is supposed to be.

Randall
On Jul 10, 2020, at 13:44, danielb987 <db123@...> wrote:

I have this problem with JMRI master.

Is there a way to see which java files that don't have any class file? And how do I fix it?

It would be great if a check that ensures that every java file has a class file is added to CI so that a developer would be notified about it before a PR is merged into master.

Daniel

2020-07-10 19:27 skrev Randall Wood via groups.io:
Some .java source has no corresponding .class file after compilation.
Randall
On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:
I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.
If I run:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
and when it's done, run the same command again without changing anything:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.
I have tried "ant realclean" but it makes no difference.
Any idea of what is wrong?
Daniel



Bob Jacobsen
@BobJacobsen


danielb987
 

I think I have a simple solution to both the problem of finding the problematic java file and the problem about checking it in CI:

If I do a:

mvn clean compile

and then a:

mvn -X compile | grep "Stale source detected"

I get the line:

[DEBUG] Stale source detected: /home/daniel/Dokument/GitHub/JMRI/java/src/apps/jmrit/package-info.java



So if we add a test to CI that does:

mvn clean compile
mvn -X compile | grep "Stale source detected" > check_stale_source.txt

we should have the file "check_stale_source.txt" empty. If it isn't, we can print it and let CI to fail.

Daniel


2020-07-10 20:12 skrev Randall Wood via groups.io:

.class files are the result of compiling the project and are not
checked into code. It is not a compilation error that a .java file
does not result in a .class file (nor is it a compilation error that a
.java file compiles multiple .class files). It does however, make it
really difficult for a build tool to determine that sources are
compiled and current (especially since we also derive .java sources to
compile from other non-.java sources).
How it gets fixed depends entirely on what the source is supposed to be.
Randall
On Jul 10, 2020, at 13:44, danielb987 <db123@...> wrote:
I have this problem with JMRI master.
Is there a way to see which java files that don't have any class file? And how do I fix it?
It would be great if a check that ensures that every java file has a class file is added to CI so that a developer would be notified about it before a PR is merged into master.
Daniel
2020-07-10 19:27 skrev Randall Wood via groups.io:
Some .java source has no corresponding .class file after compilation.
Randall
On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:
I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.
If I run:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
and when it's done, run the same command again without changing anything:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.
I have tried "ant realclean" but it makes no difference.
Any idea of what is wrong?
Daniel


Bob Jacobsen
 

Nice.

Lots of package-info.java files end with something like:

* @see jmri.managers
* @see jmri.implementation
*/
// include empty DefaultAnnotation to avoid excessive recompilation
@edu.umd.cs.findbugs.annotations.DefaultAnnotation(value={})
package jmri;

But java/src/apps/jmrit/package-info.java doesn’t. Does adding that fix this case?

Bob



On Jul 10, 2020, at 12:05 PM, danielb987 <db123@...> wrote:

I think I have a simple solution to both the problem of finding the problematic java file and the problem about checking it in CI:

If I do a:

mvn clean compile

and then a:

mvn -X compile | grep "Stale source detected"

I get the line:

[DEBUG] Stale source detected: /home/daniel/Dokument/GitHub/JMRI/java/src/apps/jmrit/package-info.java



So if we add a test to CI that does:

mvn clean compile
mvn -X compile | grep "Stale source detected" > check_stale_source.txt

we should have the file "check_stale_source.txt" empty. If it isn't, we can print it and let CI to fail.

Daniel


2020-07-10 20:12 skrev Randall Wood via groups.io:
.class files are the result of compiling the project and are not
checked into code. It is not a compilation error that a .java file
does not result in a .class file (nor is it a compilation error that a
.java file compiles multiple .class files). It does however, make it
really difficult for a build tool to determine that sources are
compiled and current (especially since we also derive .java sources to
compile from other non-.java sources).
How it gets fixed depends entirely on what the source is supposed to be.
Randall
On Jul 10, 2020, at 13:44, danielb987 <db123@...> wrote:
I have this problem with JMRI master.
Is there a way to see which java files that don't have any class file? And how do I fix it?
It would be great if a check that ensures that every java file has a class file is added to CI so that a developer would be notified about it before a PR is merged into master.
Daniel
2020-07-10 19:27 skrev Randall Wood via groups.io:
Some .java source has no corresponding .class file after compilation.
Randall
On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:
I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.
If I run:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
and when it's done, run the same command again without changing anything:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.
I have tried "ant realclean" but it makes no difference.
Any idea of what is wrong?
Daniel

Bob Jacobsen
@BobJacobsen


danielb987
 

Yes. See PR #8820 that fixes this package-file.

https://github.com/JMRI/JMRI/pull/8820

It's ready to be merged once CI passes.

Daniel

2020-07-10 21:08 skrev Bob Jacobsen:

Nice.
Lots of package-info.java files end with something like:
* @see jmri.managers
* @see jmri.implementation
*/
// include empty DefaultAnnotation to avoid excessive recompilation
@edu.umd.cs.findbugs.annotations.DefaultAnnotation(value={})
package jmri;
But java/src/apps/jmrit/package-info.java doesn’t. Does adding that
fix this case?
Bob

On Jul 10, 2020, at 12:05 PM, danielb987 <db123@...> wrote:
I think I have a simple solution to both the problem of finding the problematic java file and the problem about checking it in CI:
If I do a:
mvn clean compile
and then a:
mvn -X compile | grep "Stale source detected"
I get the line:
[DEBUG] Stale source detected: /home/daniel/Dokument/GitHub/JMRI/java/src/apps/jmrit/package-info.java
So if we add a test to CI that does:
mvn clean compile
mvn -X compile | grep "Stale source detected" > check_stale_source.txt
we should have the file "check_stale_source.txt" empty. If it isn't, we can print it and let CI to fail.
Daniel
2020-07-10 20:12 skrev Randall Wood via groups.io:
.class files are the result of compiling the project and are not
checked into code. It is not a compilation error that a .java file
does not result in a .class file (nor is it a compilation error that a
.java file compiles multiple .class files). It does however, make it
really difficult for a build tool to determine that sources are
compiled and current (especially since we also derive .java sources to
compile from other non-.java sources).
How it gets fixed depends entirely on what the source is supposed to be.
Randall
On Jul 10, 2020, at 13:44, danielb987 <db123@...> wrote:
I have this problem with JMRI master.
Is there a way to see which java files that don't have any class file? And how do I fix it?
It would be great if a check that ensures that every java file has a class file is added to CI so that a developer would be notified about it before a PR is merged into master.
Daniel
2020-07-10 19:27 skrev Randall Wood via groups.io:
Some .java source has no corresponding .class file after compilation.
Randall
On Jul 10, 2020, at 13:18, danielb987 <db123@...> wrote:
I have the problem that every time I run maven, it tells "Changes detected - recompiling the module!" and recompiles everything, even if no changes are done to the code.
If I run:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
and when it's done, run the same command again without changing anything:
mvn test -Dtest=jmri.jmrit.beantable.LogixTableActionTest
it still say "Changes detected - recompiling the module!". This happens both when I run maven from NetBeans and when I run maven from the command line.
I have tried "ant realclean" but it makes no difference.
Any idea of what is wrong?
Daniel

Bob Jacobsen
@BobJacobsen