Skip to content

Commit f4a8a54

Browse files
jorsolgnodet
andauthoredFeb 13, 2023
[MCOMPILER-525] Incorrect detection of dependency change (#172)
Signed-off-by: Jorge Solórzano <jorsol@gmail.com> Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
1 parent 86b9f59 commit f4a8a54

File tree

5 files changed

+164
-1
lines changed

5 files changed

+164
-1
lines changed
 
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# NOTE: The first time, we run up to "integration-test" phase which includes the AntRun execution which saves the
19+
# timestamp of the first JAR for comparison with the timestamp of the JAR from the final "package" invocation.
20+
# Note:
21+
invoker.goals = clean integration-test package -Dmaven.compiler.showCompilationChanges=true

‎src/it/MCOMPILER-525/pom.xml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<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/maven-v4_0_0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>MCOMPILER-525-no-recreation</artifactId>
24+
<name>MCOMPILER-525-no-recreation</name>
25+
<packaging>jar</packaging>
26+
<version>1.0-SNAPSHOT</version>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>@project.version@</version>
34+
</plugin>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-jar-plugin</artifactId>
38+
<version>3.3.0</version>
39+
</plugin>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-antrun-plugin</artifactId>
43+
<version>3.1.0</version>
44+
<executions>
45+
<execution>
46+
<id>touch</id>
47+
<phase>integration-test</phase>
48+
<goals>
49+
<goal>run</goal>
50+
</goals>
51+
<configuration>
52+
<target>
53+
<!-- Save the JAR and especially its timestamp for evaluation by the post-build hook script -->
54+
<copy file="target/MCOMPILER-525-no-recreation-1.0-SNAPSHOT.jar"
55+
tofile="target/reference.jar"
56+
preservelastmodified="true" overwrite="true"/>
57+
</target>
58+
</configuration>
59+
</execution>
60+
</executions>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package myproject;
20+
21+
/**
22+
* The classic Hello World App.
23+
*/
24+
public class HelloWorld {
25+
26+
/**
27+
* Main method.
28+
*
29+
* @param args Not used
30+
*/
31+
public static void main(String[] args) {
32+
System.out.println("Hi!");
33+
}
34+
}

‎src/it/MCOMPILER-525/verify.groovy

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
import java.nio.file.*;
22+
import java.time.*;
23+
import java.time.temporal.*
24+
import java.util.*;
25+
26+
File target = new File( basedir, "target" );
27+
assert target.isDirectory()
28+
29+
File jarFile = new File( target, "MCOMPILER-525-no-recreation-1.0-SNAPSHOT.jar" );
30+
assert jarFile.isFile()
31+
32+
File refFile = new File( target, "reference.jar" );
33+
assert refFile.isFile()
34+
35+
Instant referenceTimestamp = Files.getLastModifiedTime( refFile.toPath() )
36+
.toInstant().truncatedTo( ChronoUnit.MILLIS );
37+
System.out.println( "Reference timestamp: " + referenceTimestamp );
38+
39+
Instant actualTimestamp = Files.getLastModifiedTime( jarFile.toPath() )
40+
.toInstant().truncatedTo( ChronoUnit.MILLIS );
41+
System.out.println( "Actual timestamp : " + actualTimestamp );
42+
43+
assert referenceTimestamp.equals(actualTimestamp),
44+
"Timestamps don't match, JAR was recreated although contents has not changed"

‎src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ protected boolean isDependencyChanged() {
15381538
for (String pathElement : pathElements) {
15391539
File artifactPath = new File(pathElement);
15401540
if (artifactPath.isDirectory() || artifactPath.isFile()) {
1541-
if (hasNewFile(artifactPath, buildStartTime)) {
1541+
if (!artifactPath.equals(getOutputDirectory()) && hasNewFile(artifactPath, buildStartTime)) {
15421542
if (showCompilationChanges) {
15431543
getLog().info("New dependency detected: " + artifactPath.getAbsolutePath());
15441544
} else {

0 commit comments

Comments
 (0)