jira-importer opened a new issue, #300:
URL: https://github.com/apache/maven-build-cache-extension/issues/300

   **[Miguel 
Ortega](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER298944)**
 opened 
**[MBUILDCACHE-44](https://issues.apache.org/jira/browse/MBUILDCACHE-44?redirect=false)**
 and commented
   
   When running maven with a duplicate maven goal like below (i'm aware that 
compile phase here is not necessary)
   
   ```java
   mvn compile test
   ```
   
   the plugin seems to create a cache key that cause an error if i call.
   
   ```java
   mvn test
   ```
   
   This will cause the following error:
   
   ```java
   [ERROR] Failed to restore project
   java.lang.IllegalStateException: Duplicate key 
default-resources:resources:process-resources:maven-resources-plugin:org.apache.maven.plugins
 (attempted merging values 
org.apache.maven.buildcache.xml.build.CompletedExecution@1e1b061 and 
org.apache.maven.buildcache.xml.build.CompletedExecution@38f77cd9)  
       at java.util.stream.Collectors.duplicateKeyException 
(Collectors.java:135)
       at java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1 
(Collectors.java:182)
       at java.util.stream.ReduceOps$3ReducingSink.accept (ReduceOps.java:169)
       at java.util.ArrayList$ArrayListSpliterator.forEachRemaining 
(ArrayList.java:1625)
       at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
       at java.util.stream.AbstractPipeline.wrapAndCopyInto 
(AbstractPipeline.java:499)
       at java.util.stream.ReduceOps$ReduceOp.evaluateSequential 
(ReduceOps.java:921)
       at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
       at java.util.stream.ReferencePipeline.collect 
(ReferencePipeline.java:682)
       at org.apache.maven.buildcache.xml.Build.getExecutionMap (Build.java:198)
       at org.apache.maven.buildcache.xml.Build.hasCompletedExecution 
(Build.java:116)
       at org.apache.maven.buildcache.xml.Build.lambda$getMissingExecutions$0 
(Build.java:110)
       at java.util.stream.ReferencePipeline$2$1.accept 
(ReferencePipeline.java:178)
       at java.util.ArrayList$ArrayListSpliterator.forEachRemaining 
(ArrayList.java:1625)
       at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:509)
       at java.util.stream.AbstractPipeline.wrapAndCopyInto 
(AbstractPipeline.java:499)
       at java.util.stream.ReduceOps$ReduceOp.evaluateSequential 
(ReduceOps.java:921)
       at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:234)
       at java.util.stream.ReferencePipeline.collect 
(ReferencePipeline.java:682)
       at org.apache.maven.buildcache.xml.Build.getMissingExecutions 
(Build.java:111)
       at org.apache.maven.buildcache.CacheControllerImpl.analyzeResult 
(CacheControllerImpl.java:267)
       at org.apache.maven.buildcache.CacheControllerImpl.findLocalBuild 
(CacheControllerImpl.java:234)
       at org.apache.maven.buildcache.CacheControllerImpl.findCachedBuild 
(CacheControllerImpl.java:185)
       at org.apache.maven.buildcache.BuildCacheMojosExecutionStrategy.execute 
(BuildCacheMojosExecutionStrategy.java:114)
       at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
(MojoExecutor.java:160)
       at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
(LifecycleModuleBuilder.java:105)
       at 
org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
(LifecycleModuleBuilder.java:73)
       at 
org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build
 (SingleThreadedBuilder.java:53)
       at org.apache.maven.lifecycle.internal.LifecycleStarter.execute 
(LifecycleStarter.java:118)
       at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:260)
       at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:172)
       at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:100)
       at org.apache.maven.cli.MavenCli.execute (MavenCli.java:821)
       at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:270)
       at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke 
(NativeMethodAccessorImpl.java:77)
       at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke 
(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke (Method.java:568)
       at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced 
(Launcher.java:282)
       at org.codehaus.plexus.classworlds.launcher.Launcher.launch 
(Launcher.java:225)
       at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode 
(Launcher.java:406)
       at org.codehaus.plexus.classworlds.launcher.Launcher.main 
(Launcher.java:347)
    
   ```
   
    
   
   **+Steps to reproduce:+**
   * From a simple maven project (repo project attached), with clean cache, run 
duplicate phase `mvn compile test`
   * Then run `mvn test`
   *  -> An exception is thown and no cache is used
   * Running either of the commands again work as expected
   
   +**Expected Behaviour:**+
   
   Even in case of wrong user input like in this example, i guess i would 
expect:
   * A cache to not throw exception an reuse the 'test' cache from the first 
command
   * Or a more explicit error to explain severity or resolution to the user
   
   Environment:
   
   ```
   Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
   Maven home: <REDACTED>
   Java version: 17.0.1, vendor: Eclipse Adoptium, runtime: 
C:\<REDACTED>\jdk-17.0.1.12-hotspot
   Default locale: fr_FR, platform encoding: Cp1252
   OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
   ```
   
   +**Suggested source problem & fix**+
   
   The source problem seems to be that method "buildExecutionInfo" can return a 
list with duplicate "CompletedExecution" (same execution key)
   
   My suggested fix would be to either to deduplicate the "CompletedExecution" 
by
   
   "executionKey" CacheControllerImpl.buildExecutionInfo or change the unicity 
key for 
   CompletedExecution.
   
   I could work on a PR if bug is confirmed and suggested fix is validated.
   
   
   ---
   
   **Affects:** 1.0.0
   
   **Attachments:**
   - 
[maven-cache.zip](https://issues.apache.org/jira/secure/attachment/13055414/maven-cache.zip)
 (_7.56 kB_)
   
   **Remote Links:**
   - [GitHub Pull Request #52
   ](https://github.com/apache/maven-build-cache-extension/pull/52)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to