You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2023/02/13 10:00:55 UTC
[maven-compiler-plugin] branch master updated: [MCOMPILER-525] Incorrect detection of dependency change (#172)
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new f4a8a54 [MCOMPILER-525] Incorrect detection of dependency change (#172)
f4a8a54 is described below
commit f4a8a54e116b07e888ac7b6371fa24b7a81517b3
Author: Jorge Solórzano <jo...@gmail.com>
AuthorDate: Mon Feb 13 11:00:49 2023 +0100
[MCOMPILER-525] Incorrect detection of dependency change (#172)
Signed-off-by: Jorge Solórzano <jo...@gmail.com>
Co-authored-by: Guillaume Nodet <gn...@gmail.com>
---
src/it/MCOMPILER-525/invoker.properties | 21 +++++++
src/it/MCOMPILER-525/pom.xml | 64 ++++++++++++++++++++++
.../src/main/java/myproject/HelloWorld.java | 34 ++++++++++++
src/it/MCOMPILER-525/verify.groovy | 44 +++++++++++++++
.../plugin/compiler/AbstractCompilerMojo.java | 2 +-
5 files changed, 164 insertions(+), 1 deletion(-)
diff --git a/src/it/MCOMPILER-525/invoker.properties b/src/it/MCOMPILER-525/invoker.properties
new file mode 100644
index 0000000..da0f092
--- /dev/null
+++ b/src/it/MCOMPILER-525/invoker.properties
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# NOTE: The first time, we run up to "integration-test" phase which includes the AntRun execution which saves the
+# timestamp of the first JAR for comparison with the timestamp of the JAR from the final "package" invocation.
+# Note:
+invoker.goals = clean integration-test package -Dmaven.compiler.showCompilationChanges=true
diff --git a/src/it/MCOMPILER-525/pom.xml b/src/it/MCOMPILER-525/pom.xml
new file mode 100644
index 0000000..48de91e
--- /dev/null
+++ b/src/it/MCOMPILER-525/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>MCOMPILER-525-no-recreation</artifactId>
+ <name>MCOMPILER-525-no-recreation</name>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.3.0</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>3.1.0</version>
+ <executions>
+ <execution>
+ <id>touch</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <!-- Save the JAR and especially its timestamp for evaluation by the post-build hook script -->
+ <copy file="target/MCOMPILER-525-no-recreation-1.0-SNAPSHOT.jar"
+ tofile="target/reference.jar"
+ preservelastmodified="true" overwrite="true"/>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java b/src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java
new file mode 100644
index 0000000..8318e9f
--- /dev/null
+++ b/src/it/MCOMPILER-525/src/main/java/myproject/HelloWorld.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package myproject;
+
+/**
+ * The classic Hello World App.
+ */
+public class HelloWorld {
+
+ /**
+ * Main method.
+ *
+ * @param args Not used
+ */
+ public static void main(String[] args) {
+ System.out.println("Hi!");
+ }
+}
diff --git a/src/it/MCOMPILER-525/verify.groovy b/src/it/MCOMPILER-525/verify.groovy
new file mode 100644
index 0000000..0e97225
--- /dev/null
+++ b/src/it/MCOMPILER-525/verify.groovy
@@ -0,0 +1,44 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.nio.file.*;
+import java.time.*;
+import java.time.temporal.*
+import java.util.*;
+
+File target = new File( basedir, "target" );
+assert target.isDirectory()
+
+File jarFile = new File( target, "MCOMPILER-525-no-recreation-1.0-SNAPSHOT.jar" );
+assert jarFile.isFile()
+
+File refFile = new File( target, "reference.jar" );
+assert refFile.isFile()
+
+Instant referenceTimestamp = Files.getLastModifiedTime( refFile.toPath() )
+ .toInstant().truncatedTo( ChronoUnit.MILLIS );
+System.out.println( "Reference timestamp: " + referenceTimestamp );
+
+Instant actualTimestamp = Files.getLastModifiedTime( jarFile.toPath() )
+ .toInstant().truncatedTo( ChronoUnit.MILLIS );
+System.out.println( "Actual timestamp : " + actualTimestamp );
+
+assert referenceTimestamp.equals(actualTimestamp),
+ "Timestamps don't match, JAR was recreated although contents has not changed"
diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index aff9059..ad68b4f 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -1538,7 +1538,7 @@ public abstract class AbstractCompilerMojo extends AbstractMojo {
for (String pathElement : pathElements) {
File artifactPath = new File(pathElement);
if (artifactPath.isDirectory() || artifactPath.isFile()) {
- if (hasNewFile(artifactPath, buildStartTime)) {
+ if (!artifactPath.equals(getOutputDirectory()) && hasNewFile(artifactPath, buildStartTime)) {
if (showCompilationChanges) {
getLog().info("New dependency detected: " + artifactPath.getAbsolutePath());
} else {