[ 
https://issues.apache.org/jira/browse/MCOMPILER-561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17799160#comment-17799160
 ] 

ASF GitHub Bot commented on MCOMPILER-561:
------------------------------------------

slawekjaranowski commented on code in PR #219:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/219#discussion_r1433140742


##########
src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java:
##########
@@ -1842,6 +1851,48 @@ private boolean 
hasInputFileTreeChanged(IncrementalBuildHelper ibh, Set<File> in
         return inputTreeChanges.hasChanged();
     }
 
+    private static final int MAX_FILE_WALK_LIMIT = 20;
+
+    /**
+     * Performs a check on compiled class files to ensure that the bytecode 
version
+     * hasn't changed between runs.
+     *
+     * <p>This is limited to check a maximum of {@link #MAX_FILE_WALK_LIMIT}.
+     *
+     * @return true if a bytecode version differs from the actual release 
version.
+     */
+    private boolean hasBytecodeChanged() {
+        String currentVersion = getVersionRelease();
+        JavaVersion javaVersion = JavaVersion.parse(currentVersion).asMajor();
+
+        try (Stream<Path> walk = Files.walk(getOutputDirectory().toPath())) {
+            Map<Path, JavaClassfileVersion> pathVersionMap = walk.filter(file 
-> "class"
+                            
.equals(FileUtils.extension(file.getFileName().toString())))
+                    .limit(MAX_FILE_WALK_LIMIT)
+                    .collect(Collectors.toMap(Function.identity(), 
JavaClassfileVersion::of));

Review Comment:
   Maybe instead of checking bytecode of classes we can store current JDK 
version used to compile and next time verify if is the same.
   
   We also should add an IT for multi-releases compilation.





> Add new rebuild detection for bytecode changes
> ----------------------------------------------
>
>                 Key: MCOMPILER-561
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-561
>             Project: Maven Compiler Plugin
>          Issue Type: New Feature
>    Affects Versions: 3.11.0, 3.12.0
>            Reporter: Jorge Solórzano
>            Priority: Major
>
> If the source code changes the bytecode version, it should trigger a rebuild.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to