You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2022/02/03 11:38:05 UTC
[maven-compiler-plugin] branch master updated: [MCOMPILER-474] - Also check jar files when determining if dependencies changed (#73)
This is an automated email from the ASF dual-hosted git repository.
olamy 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 408f0e3 [MCOMPILER-474] - Also check jar files when determining if dependencies changed (#73)
408f0e3 is described below
commit 408f0e32057a7e51c93f17ee1bb919be0347d63d
Author: Roman Kozlov <ko...@gmail.com>
AuthorDate: Thu Feb 3 14:37:57 2022 +0300
[MCOMPILER-474] - Also check jar files when determining if dependencies changed (#73)
---
.../dependent-module/pom.xml | 42 ++++++++++++
.../dependent-module/src/main/java/Main.java | 27 ++++++++
.../invoker.properties | 21 ++++++
.../pom.xml | 79 ++++++++++++++++++++++
.../service/pom.xml | 34 ++++++++++
.../service/src/main/java/TestService.java | 27 ++++++++
.../verify.groovy | 24 +++++++
.../plugin/compiler/AbstractCompilerMojo.java | 10 ++-
8 files changed, 258 insertions(+), 6 deletions(-)
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/dependent-module/pom.xml b/src/it/MCOMPILER-474_recompile-dependent-when-package/dependent-module/pom.xml
new file mode 100644
index 0000000..5ca1668
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/dependent-module/pom.xml
@@ -0,0 +1,42 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>mcompiler-474-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>dependent-module</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>service</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/dependent-module/src/main/java/Main.java b/src/it/MCOMPILER-474_recompile-dependent-when-package/dependent-module/src/main/java/Main.java
new file mode 100644
index 0000000..dbad7cf
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/dependent-module/src/main/java/Main.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+public class Main
+{
+ public static void main( String[] args )
+ {
+ TestService testService = new TestService();
+ testService.run();
+ }
+}
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/invoker.properties b/src/it/MCOMPILER-474_recompile-dependent-when-package/invoker.properties
new file mode 100644
index 0000000..f0faec3
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/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.
+
+invoker.goals = clean package
+invoker.goals.2 = groovy:execute
+invoker.goals.3 = package
+invoker.buildResult.3 = failure
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/pom.xml b/src/it/MCOMPILER-474_recompile-dependent-when-package/pom.xml
new file mode 100644
index 0000000..fd7035b
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/pom.xml
@@ -0,0 +1,79 @@
+<?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.compiler.it</groupId>
+ <artifactId>mcompiler-474-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>
+ Integration test to verify that dependent-module is recompiled when run 'mvn package' without 'clean'
+ if module dependency changed.
+ The compilation should fail as dependent-module uses method that no longer exists (run() method of TestService
+ renamed to newMethodName()).
+ </description>
+
+ <modules>
+ <module>dependent-module</module>
+ <module>service</module>
+ </modules>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>groovy-maven-plugin</artifactId>
+ <version>2.0</version>
+ <configuration>
+ <source>
+ def fileToModify = new File(project.basedir, 'service/src/main/java/TestService.java')
+ processFileInplace(fileToModify) { text ->
+ text.replaceAll(/run/, 'newMethodName')
+ }
+
+ def processFileInplace(file, Closure processText) {
+ file.write(processText(file.text))
+ }
+ </source>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>2.4.21</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/service/pom.xml b/src/it/MCOMPILER-474_recompile-dependent-when-package/service/pom.xml
new file mode 100644
index 0000000..26b2c87
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/service/pom.xml
@@ -0,0 +1,34 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.compiler.it</groupId>
+ <artifactId>mcompiler-474-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>service</artifactId>
+
+</project>
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/service/src/main/java/TestService.java b/src/it/MCOMPILER-474_recompile-dependent-when-package/service/src/main/java/TestService.java
new file mode 100644
index 0000000..7d5e878
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/service/src/main/java/TestService.java
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+public class TestService
+{
+
+ public void run()
+ {
+
+ }
+}
diff --git a/src/it/MCOMPILER-474_recompile-dependent-when-package/verify.groovy b/src/it/MCOMPILER-474_recompile-dependent-when-package/verify.groovy
new file mode 100644
index 0000000..11789f7
--- /dev/null
+++ b/src/it/MCOMPILER-474_recompile-dependent-when-package/verify.groovy
@@ -0,0 +1,24 @@
+
+/*
+ * 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.
+ */
+def logFile = new File( basedir, 'build.log' )
+assert logFile.exists()
+content = logFile.text
+
+assert content.contains( 'COMPILATION ERROR :' )
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 93fa6aa..5b3b09c 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -493,8 +493,8 @@ public abstract class AbstractCompilerMojo
private MojoExecution mojoExecution;
/**
- * file extensions to check timestamp for incremental build
- * <b>default contains only <code>class</code></b>
+ * File extensions to check timestamp for incremental build.
+ * Default contains only <code>class</code> and <code>jar</code>.
*
* @since 3.1
*/
@@ -1603,7 +1603,7 @@ public abstract class AbstractCompilerMojo
if ( fileExtensions == null || fileExtensions.isEmpty() )
{
- fileExtensions = Collections.singletonList( "class" );
+ fileExtensions = Collections.unmodifiableList( Arrays.asList( "class", "jar" ) );
}
Date buildStartTime = getBuildStartTime();
@@ -1614,10 +1614,8 @@ public abstract class AbstractCompilerMojo
for ( String pathElement : pathElements )
{
- // ProjectArtifacts are artifacts which are available in the local project
- // that's the only ones we are interested in now.
File artifactPath = new File( pathElement );
- if ( artifactPath.isDirectory() )
+ if ( artifactPath.isDirectory() || artifactPath.isFile() )
{
if ( hasNewFile( artifactPath, buildStartTime ) )
{