diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index 72bc0300f1..b229581e5c 100644
--- a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -106,6 +106,7 @@ public static Test suite()
// -------------------------------------------------------------------------------------------------------------
// suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
+ suite.addTestSuite( MavenITmng5640LifecycleParticipantAfterSessionEnd.class );
suite.addTestSuite( MavenITmng5608ProfileActivationWarningTest.class );
suite.addTestSuite( MavenITmng5591WorkspaceReader.class );
suite.addTestSuite( MavenITmng5581LifecycleMappingDelegate.class );
diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java
new file mode 100644
index 0000000000..d0151cd220
--- /dev/null
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5640LifecycleParticipantAfterSessionEnd.java
@@ -0,0 +1,66 @@
+package org.apache.maven.it;
+
+/*
+ * 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.io.File;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * IT that verifies that lifecycle participant afterSessionEnd
+ * method is invoked even with build failure.
+ */
+public class MavenITmng5640LifecycleParticipantAfterSessionEnd
+ extends AbstractMavenIntegrationTestCase
+{
+ public MavenITmng5640LifecycleParticipantAfterSessionEnd()
+ {
+ super( "[3.2.2,)" );
+ }
+
+ public void test()
+ throws Exception
+ {
+ File testDir =
+ ResourceExtractor.simpleExtractResources( getClass(), "/mng-5640-lifecycleParticipant-afterSession" );
+ File extensionDir = new File( testDir, "extension" );
+ File projectDir = new File( testDir, "basic" );
+
+ Verifier verifier;
+
+ // install the test plugin
+ verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
+ verifier.executeGoal( "install" );
+ verifier.resetStreams();
+ verifier.verifyErrorFreeLog();
+
+ // build the test project
+ verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
+ try {
+ verifier.executeGoal("package");
+ } catch (VerificationException e) {
+ // expected, as the build will fail due to always failing UT
+ }
+ verifier.resetStreams();
+ verifier.verifyTextInLog("testApp(org.apache.maven.its.mng5640.FailingTest)");
+
+ verifier.assertFilePresent( "target/afterSessionEnd.txt" );
+ }
+}
diff --git a/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml
new file mode 100644
index 0000000000..fea98e05da
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/pom.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng5640.lifecycleParticipantAfterSession
+ mng-5640-lifecycleParticipant-afterSession-basic
+ 0.1
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
+
+
+
+ org.apache.maven.its.mng5640.lifecycleParticipantAfterSession
+ mng-5640-lifecycleParticipant-afterSession-extension
+ 0.1
+
+
+
+
diff --git a/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java
new file mode 100644
index 0000000000..3f2dd98388
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/basic/src/test/java/org/apache/maven/its/mng5640/FailingTest.java
@@ -0,0 +1,18 @@
+package org.apache.maven.its.mng5640;
+
+import junit.framework.TestCase;
+
+/**
+ * Always failing UT.
+ */
+public class FailingTest
+ extends TestCase
+{
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( false );
+ }
+}
diff --git a/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml
new file mode 100644
index 0000000000..ec97934bb0
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/pom.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+ 4.0.0
+
+ org.apache.maven.its.mng5640.lifecycleParticipantAfterSession
+ mng-5640-lifecycleParticipant-afterSession-extension
+ 0.1
+
+
+ 3.2.1
+
+
+
+
+ org.apache.maven
+ maven-core
+ ${maven-version}
+ provided
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.0.2
+
+
+ 1.5
+
+
+
+ org.sonatype.plugins
+ sisu-maven-plugin
+ 1.1
+
+
+
+ main-index
+ test-index
+
+
+
+
+
+
+
diff --git a/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java
new file mode 100644
index 0000000000..1dabb2eaa3
--- /dev/null
+++ b/its/core-it-suite/src/test/resources/mng-5640-lifecycleParticipant-afterSession/extension/src/main/java/org/apache/maven/its/mng5640/lifecycleParticipantAfterSession/LifecycleParticipantImpl.java
@@ -0,0 +1,69 @@
+package org.apache.maven.its.mng5640.lifecycleParticipantAfterSession;
+
+/*
+ * 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.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.apache.maven.AbstractMavenLifecycleParticipant;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.logging.Logger;
+
+@Named
+@Singleton
+public class LifecycleParticipantImpl
+ extends AbstractMavenLifecycleParticipant
+{
+ private final Logger log;
+
+ @Inject
+ public LifecycleParticipantImpl( Logger log )
+ {
+ this.log = log;
+ }
+
+ @Override
+ public void afterSessionEnd( MavenSession session )
+ {
+ MavenProject project = session.getProjects().get( 0 );
+
+ File target = new File( project.getBuild().getDirectory() );
+ File marker = new File( target, "afterSessionEnd.txt" );
+
+ if ( !target.exists() && !target.getParentFile().mkdirs() )
+ {
+ log.error( "Could not create directory " + target );
+ }
+ try
+ {
+ new FileOutputStream( marker ).close();
+ }
+ catch ( IOException e )
+ {
+ log.error( "Could not create marker file " + marker, e );
+ }
+ }
+}