You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/07/11 22:33:37 UTC

[maven-dependency-analyzer] branch master updated: [MDEP-708] - dependency:analyze recommends test scope for test-only artifacts that have non-test scope (#14)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d3aa86  [MDEP-708] - dependency:analyze recommends test scope for test-only artifacts that have non-test scope (#14)
6d3aa86 is described below

commit 6d3aa8652ad9219c4bbe6d0e96238ed6a5b2327d
Author: ian-lavallee <34...@users.noreply.github.com>
AuthorDate: Sat Jul 11 18:33:27 2020 -0400

    [MDEP-708] - dependency:analyze recommends test scope for test-only artifacts that have non-test scope (#14)
    
    * jarWithNonTestScopedTestDependency not working
    
    * working test, need to rename
    
    * working test
    
    * PR comment changes
    
    * changing protected methods to private in analyzer
    
    * fix xml spacing
    
    * test fix for CI
---
 .../analyzer/DefaultProjectDependencyAnalyzer.java | 56 +++++++++++++++++---
 .../analyzer/ProjectDependencyAnalysis.java        | 51 +++++++++++++++---
 .../DefaultProjectDependencyAnalyzerTest.java      | 59 +++++++++++++++++----
 .../analyzer/ProjectDependencyAnalysisTest.java    |  4 +-
 .../pom.xml                                        | 28 +++++-----
 .../project1}/pom.xml                              | 23 ++++----
 .../jarWithTestDependency/project1/Project1.java   | 36 +++++++++++++
 .../project2/pom.xml                               | 61 ++++++++++++++++++++++
 .../jarWithTestDependency/project2/Project2.java   | 43 +++++++++++++++
 src/test/resources/jarWithTestDependency/pom.xml   |  4 +-
 10 files changed, 312 insertions(+), 53 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
index f0e92c4..a59cba8 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java
@@ -73,10 +73,14 @@ public class DefaultProjectDependencyAnalyzer
 
             Set<String> dependencyClasses = buildDependencyClasses( project );
 
+            Set<String> testOnlyDependencyClasses = buildTestDependencyClasses( project );
+
             Set<Artifact> declaredArtifacts = buildDeclaredArtifacts( project );
 
             Set<Artifact> usedArtifacts = buildUsedArtifacts( artifactClassMap, dependencyClasses );
 
+            Set<Artifact> testOnlyArtifacts = buildUsedArtifacts( artifactClassMap, testOnlyDependencyClasses );
+
             Set<Artifact> usedDeclaredArtifacts = new LinkedHashSet<Artifact>( declaredArtifacts );
             usedDeclaredArtifacts.retainAll( usedArtifacts );
 
@@ -86,8 +90,10 @@ public class DefaultProjectDependencyAnalyzer
             Set<Artifact> unusedDeclaredArtifacts = new LinkedHashSet<Artifact>( declaredArtifacts );
             unusedDeclaredArtifacts = removeAll( unusedDeclaredArtifacts, usedArtifacts );
 
+            Set<Artifact> testArtifactsWithNonTestScope = getTestArtifactsWithNonTestScope( testOnlyArtifacts );
+
             return new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts,
-                                                  unusedDeclaredArtifacts );
+                                                  unusedDeclaredArtifacts, testArtifactsWithNonTestScope );
         }
         catch ( IOException exception )
         {
@@ -129,7 +135,22 @@ public class DefaultProjectDependencyAnalyzer
         return results;
     }
 
-    protected Map<Artifact, Set<String>> buildArtifactClassMap( MavenProject project )
+    private Set<Artifact> getTestArtifactsWithNonTestScope( Set<Artifact> testOnlyArtifacts )
+    {
+        Set<Artifact> nonTestScopeArtifacts = new LinkedHashSet<Artifact>();
+
+        for ( Artifact artifact : testOnlyArtifacts )
+        {
+            if ( !artifact.getScope().equals( "test" ) )
+            {
+                nonTestScopeArtifacts.add( artifact );
+            }
+        }
+
+        return nonTestScopeArtifacts;
+    }
+
+    private Map<Artifact, Set<String>> buildArtifactClassMap( MavenProject project )
         throws IOException
     {
         Map<Artifact, Set<String>> artifactClassMap = new LinkedHashMap<Artifact, Set<String>>();
@@ -189,7 +210,30 @@ public class DefaultProjectDependencyAnalyzer
         return artifactClassMap;
     }
 
-    protected Set<String> buildDependencyClasses( MavenProject project )
+    private Set<String> buildTestDependencyClasses( MavenProject project ) throws IOException
+    {
+        Set<String> nonTestDependencyClasses = new HashSet<>();
+        Set<String> testDependencyClasses = new HashSet<>();
+        Set<String> testOnlyDependencyClasses = new HashSet<>();
+
+        String outputDirectory = project.getBuild().getOutputDirectory();
+        nonTestDependencyClasses.addAll( buildDependencyClasses( outputDirectory ) );
+
+        String testOutputDirectory = project.getBuild().getTestOutputDirectory();
+        testDependencyClasses.addAll( buildDependencyClasses( testOutputDirectory ) );
+
+        for ( String testString : testDependencyClasses )
+        {
+            if ( !nonTestDependencyClasses.contains( testString ) )
+            {
+                testOnlyDependencyClasses.add( testString );
+            }
+        }
+
+        return testOnlyDependencyClasses;
+    }
+
+    private Set<String> buildDependencyClasses( MavenProject project )
         throws IOException
     {
         Set<String> dependencyClasses = new HashSet<String>();
@@ -211,7 +255,7 @@ public class DefaultProjectDependencyAnalyzer
         return dependencyAnalyzer.analyze( url );
     }
 
-    protected Set<Artifact> buildDeclaredArtifacts( MavenProject project )
+    private Set<Artifact> buildDeclaredArtifacts( MavenProject project )
     {
         @SuppressWarnings( "unchecked" )
         Set<Artifact> declaredArtifacts = project.getDependencyArtifacts();
@@ -224,7 +268,7 @@ public class DefaultProjectDependencyAnalyzer
         return declaredArtifacts;
     }
 
-    protected Set<Artifact> buildUsedArtifacts( Map<Artifact, Set<String>> artifactClassMap,
+    private Set<Artifact> buildUsedArtifacts( Map<Artifact, Set<String>> artifactClassMap,
                                               Set<String> dependencyClasses )
     {
         Set<Artifact> usedArtifacts = new HashSet<Artifact>();
@@ -242,7 +286,7 @@ public class DefaultProjectDependencyAnalyzer
         return usedArtifacts;
     }
 
-    protected Artifact findArtifactForClassName( Map<Artifact, Set<String>> artifactClassMap, String className )
+    private Artifact findArtifactForClassName( Map<Artifact, Set<String>> artifactClassMap, String className )
     {
         for ( Map.Entry<Artifact, Set<String>> entry : artifactClassMap.entrySet() )
         {
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java
index 00b1629..ecfc6d1 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.java
@@ -44,19 +44,33 @@ public class ProjectDependencyAnalysis
 
     private final Set<Artifact> unusedDeclaredArtifacts;
 
+    private final Set<Artifact> testArtifactsWithNonTestScope;
+
     // constructors -----------------------------------------------------------
 
     public ProjectDependencyAnalysis()
     {
-        this( null, null, null );
+        this( null, null, null, null );
     }
 
+    // constructor to maintain compatibility with old API
     public ProjectDependencyAnalysis( Set<Artifact> usedDeclaredArtifacts, Set<Artifact> usedUndeclaredArtifacts,
                                       Set<Artifact> unusedDeclaredArtifacts )
     {
         this.usedDeclaredArtifacts = safeCopy( usedDeclaredArtifacts );
         this.usedUndeclaredArtifacts = safeCopy( usedUndeclaredArtifacts );
         this.unusedDeclaredArtifacts = safeCopy( unusedDeclaredArtifacts );
+        this.testArtifactsWithNonTestScope = new HashSet<>();
+    }
+
+    public ProjectDependencyAnalysis( Set<Artifact> usedDeclaredArtifacts, Set<Artifact> usedUndeclaredArtifacts,
+                                      Set<Artifact> unusedDeclaredArtifacts,
+                                      Set<Artifact> testArtifactsWithNonTestScope )
+    {
+        this.usedDeclaredArtifacts = safeCopy( usedDeclaredArtifacts );
+        this.usedUndeclaredArtifacts = safeCopy( usedUndeclaredArtifacts );
+        this.unusedDeclaredArtifacts = safeCopy( unusedDeclaredArtifacts );
+        this.testArtifactsWithNonTestScope = safeCopy( testArtifactsWithNonTestScope );
     }
 
     // public methods ---------------------------------------------------------
@@ -67,7 +81,7 @@ public class ProjectDependencyAnalysis
      */
     public Set<Artifact> getUsedDeclaredArtifacts()
     {
-        return usedDeclaredArtifacts;
+        return safeCopy( usedDeclaredArtifacts );
     }
 
     /**
@@ -76,7 +90,7 @@ public class ProjectDependencyAnalysis
      */
     public Set<Artifact> getUsedUndeclaredArtifacts()
     {
-        return usedUndeclaredArtifacts;
+        return safeCopy( usedUndeclaredArtifacts );
     }
 
     /**
@@ -85,7 +99,16 @@ public class ProjectDependencyAnalysis
      */
     public Set<Artifact> getUnusedDeclaredArtifacts()
     {
-        return unusedDeclaredArtifacts;
+        return safeCopy( unusedDeclaredArtifacts );
+    }
+
+    /**
+     * Test Artifacts that have a non-test scope
+     * @return {@link Artifact}
+     */
+    public Set<Artifact> getTestArtifactsWithNonTestScope()
+    {
+        return safeCopy( testArtifactsWithNonTestScope );
     }
 
     /**
@@ -106,7 +129,8 @@ public class ProjectDependencyAnalysis
             }
         }
 
-        return new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts, filteredUnusedDeclared );
+        return new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts, filteredUnusedDeclared,
+                testArtifactsWithNonTestScope );
     }
 
     /**
@@ -169,7 +193,8 @@ public class ProjectDependencyAnalysis
             throw new ProjectDependencyAnalyzerException( "Trying to force use of dependencies which are " + builder );
         }
 
-        return new ProjectDependencyAnalysis( forcedUsedDeclared, usedUndeclaredArtifacts, forcedUnusedDeclared );
+        return new ProjectDependencyAnalysis( forcedUsedDeclared, usedUndeclaredArtifacts, forcedUnusedDeclared,
+                testArtifactsWithNonTestScope );
     }
 
     // Object methods ---------------------------------------------------------
@@ -182,6 +207,7 @@ public class ProjectDependencyAnalysis
         int hashCode = getUsedDeclaredArtifacts().hashCode();
         hashCode = ( hashCode * 37 ) + getUsedUndeclaredArtifacts().hashCode();
         hashCode = ( hashCode * 37 ) + getUnusedDeclaredArtifacts().hashCode();
+        hashCode = ( hashCode * 37 ) + getTestArtifactsWithNonTestScope().hashCode();
 
         return hashCode;
     }
@@ -197,7 +223,8 @@ public class ProjectDependencyAnalysis
 
             return getUsedDeclaredArtifacts().equals( analysis.getUsedDeclaredArtifacts() )
                 && getUsedUndeclaredArtifacts().equals( analysis.getUsedUndeclaredArtifacts() )
-                && getUnusedDeclaredArtifacts().equals( analysis.getUnusedDeclaredArtifacts() );
+                && getUnusedDeclaredArtifacts().equals( analysis.getUnusedDeclaredArtifacts() )
+                && getTestArtifactsWithNonTestScope().equals( analysis.getTestArtifactsWithNonTestScope() );
         }
 
         return false;
@@ -235,6 +262,16 @@ public class ProjectDependencyAnalysis
             buffer.append( "unusedDeclaredArtifacts=" ).append( getUnusedDeclaredArtifacts() );
         }
 
+        if ( !getTestArtifactsWithNonTestScope().isEmpty() )
+        {
+            if ( buffer.length() > 0 )
+            {
+                buffer.append( "," );
+            }
+
+            buffer.append( "testArtifactsWithNonTestScope=" ).append( getTestArtifactsWithNonTestScope() );
+        }
+
         buffer.insert( 0, "[" );
         buffer.insert( 0, getClass().getName() );
 
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
index e5b90f1..df528f9 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzerTest.java
@@ -138,7 +138,8 @@ public class DefaultProjectDependencyAnalyzerTest
         Set<Artifact> usedDeclaredArtifacts = new HashSet<Artifact>( Arrays.asList( project1, project2 ) );
 
         ProjectDependencyAnalysis expectedAnalysis =
-            new ProjectDependencyAnalysis( usedDeclaredArtifacts, new HashSet<Artifact>(), new HashSet<Artifact>() );
+            new ProjectDependencyAnalysis( usedDeclaredArtifacts, new HashSet<Artifact>(), new HashSet<Artifact>(),
+                    new HashSet<Artifact>() );
 
         assertEquals( expectedAnalysis, actualAnalysis );
     }
@@ -162,7 +163,8 @@ public class DefaultProjectDependencyAnalyzerTest
         Set<Artifact> usedDeclaredArtifacts = Collections.singleton( project1 );
 
         ProjectDependencyAnalysis expectedAnalysis =
-            new ProjectDependencyAnalysis( usedDeclaredArtifacts, new HashSet<Artifact>(), new HashSet<Artifact>() );
+            new ProjectDependencyAnalysis( usedDeclaredArtifacts, new HashSet<Artifact>(), new HashSet<Artifact>(),
+                    new HashSet<Artifact>() );
 
         assertEquals( expectedAnalysis, actualAnalysis );
     }
@@ -186,7 +188,8 @@ public class DefaultProjectDependencyAnalyzerTest
         Artifact project1 = createArtifact( "org.apache.maven.shared.dependency-analyzer.tests",
                                             "jarWithCompileDependency1", "jar", "1.0", "compile" );
         Set<Artifact> usedDeclaredArtifacts = Collections.singleton( project1 );
-        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null );
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null,
+                null );
 
         assertEquals( expectedAnalysis, actualAnalysis );
     }
@@ -242,14 +245,15 @@ public class DefaultProjectDependencyAnalyzerTest
         if ( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
         {
             Set<Artifact> usedDeclaredArtifacts = new HashSet<Artifact>( Arrays.asList( project1, junit ) );
-            expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null );
+            expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null, null );
         }
         else
         {
             // With JDK 7 and earlier, not all deps are identified correctly
             Set<Artifact> usedDeclaredArtifacts = Collections.singleton( project1 );
             Set<Artifact> unusedDeclaredArtifacts = Collections.singleton( junit );
-            expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, unusedDeclaredArtifacts );
+            expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, unusedDeclaredArtifacts,
+                    null );
         }
 
         assertEquals( expectedAnalysis, actualAnalysis );
@@ -267,12 +271,46 @@ public class DefaultProjectDependencyAnalyzerTest
         Artifact jdom = createArtifact( "dom4j", "dom4j", "jar", "1.6.1", "compile" );
         Set<Artifact> usedDeclaredArtifacts = Collections.singleton( jdom );
 
-        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null );
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null,
+                null );
 
         // MSHARED-47: usedUndeclaredArtifacts=[xml-apis:xml-apis:jar:1.0.b2:compile]
         // assertEquals( expectedAnalysis, actualAnalysis );
     }
 
+    public void testJarWithNonTestScopedTestDependency()
+            throws TestToolsException, ProjectDependencyAnalyzerException
+    {
+        compileProject( "jarWithNonTestScopedTestDependency/pom.xml" );
+
+        MavenProject project2 = getProject( "jarWithNonTestScopedTestDependency/project2/pom.xml" );
+
+        ProjectDependencyAnalysis actualAnalysis = analyzer.analyze( project2 );
+
+        Artifact artifact1 = createArtifact( "org.apache.maven.shared.dependency-analyzer.tests",
+                "jarWithNonTestScopedTestDependency1", "jar", "1.0", "test" );
+        Artifact junit = createArtifact( "junit", "junit", "jar", "3.8.1", "test" );
+
+        ProjectDependencyAnalysis expectedAnalysis;
+        if ( SystemUtils.isJavaVersionAtLeast( JavaVersion.JAVA_1_8 ) )
+        {
+            Set<Artifact> usedDeclaredArtifacts = new HashSet<>( Arrays.asList( artifact1, junit ) );
+            Set<Artifact> nonTestScopedTestArtifacts = Collections.singleton( junit );
+            expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null,
+                    nonTestScopedTestArtifacts );
+        }
+        else
+        {
+            // With JDK 7 and earlier, not all deps are identified correctly
+            Set<Artifact> usedDeclaredArtifacts = Collections.singleton( artifact1 );
+            Set<Artifact> unUsedDeclaredArtifacts = Collections.singleton( junit );
+            expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, unUsedDeclaredArtifacts,
+                    null );
+        }
+
+        assertEquals( expectedAnalysis, actualAnalysis );
+    }
+
     public void testMultimoduleProject()
         throws TestToolsException, ProjectDependencyAnalyzerException
     {
@@ -297,7 +335,8 @@ public class DefaultProjectDependencyAnalyzerTest
         Artifact junit = createArtifact( "org.apache.maven.its.dependency", "test-module1", "jar", "1.0", "compile" );
         Set<Artifact> usedDeclaredArtifacts = Collections.singleton( junit );
 
-        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null );
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis( usedDeclaredArtifacts, null, null,
+                null );
 
         assertEquals( expectedAnalysis, actualAnalysis );
     }
@@ -323,7 +362,8 @@ public class DefaultProjectDependencyAnalyzerTest
         Artifact annotation = createArtifact( "org.apache.maven.shared.dependency-analyzer.tests",
                                             "typeUseAnnotationDependencyAnnotation", "jar", "1.0", "compile" );
         Set<Artifact> usedDeclaredArtifacts = Collections.singleton( annotation );
-        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis(usedDeclaredArtifacts, null, null);
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis(usedDeclaredArtifacts, null, null,
+                null );
 
         assertEquals( expectedAnalysis, actualAnalysis );
     }
@@ -349,7 +389,8 @@ public class DefaultProjectDependencyAnalyzerTest
         Artifact annotation = createArtifact( "org.apache.maven.shared.dependency-analyzer.tests",
                                             "typeUseAnnotationDependencyAnnotation", "jar", "1.0", "compile" );
         Set<Artifact> usedDeclaredArtifacts = Collections.singleton( annotation );
-        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis(usedDeclaredArtifacts, null, null);
+        ProjectDependencyAnalysis expectedAnalysis = new ProjectDependencyAnalysis(usedDeclaredArtifacts, null, null,
+                null);
 
         assertEquals( expectedAnalysis, actualAnalysis );
     }
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java
index 8c1e3e9..8f3d7ae 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysisTest.java
@@ -43,9 +43,11 @@ public class ProjectDependencyAnalysisTest
         Set<Artifact> usedDeclaredArtifacts = new HashSet<Artifact>();
         Set<Artifact> usedUndeclaredArtifacts = new HashSet<Artifact>();
         Set<Artifact> unusedDeclaredArtifacts = new HashSet<Artifact>();
+        Set<Artifact> testArtifactsWithNonTestScope = new HashSet<Artifact>();
 
         ProjectDependencyAnalysis analysis =
-            new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts, unusedDeclaredArtifacts );
+            new ProjectDependencyAnalysis( usedDeclaredArtifacts, usedUndeclaredArtifacts, unusedDeclaredArtifacts,
+                    testArtifactsWithNonTestScope);
 
         assertEquals( usedDeclaredArtifacts, analysis.getUsedDeclaredArtifacts() );
         assertEquals( usedUndeclaredArtifacts, analysis.getUsedUndeclaredArtifacts() );
diff --git a/src/test/resources/jarWithTestDependency/pom.xml b/src/test/resources/jarWithNonTestScopedTestDependency/pom.xml
similarity index 62%
copy from src/test/resources/jarWithTestDependency/pom.xml
copy to src/test/resources/jarWithNonTestScopedTestDependency/pom.xml
index 51d6a1e..cbb658f 100644
--- a/src/test/resources/jarWithTestDependency/pom.xml
+++ b/src/test/resources/jarWithNonTestScopedTestDependency/pom.xml
@@ -20,19 +20,19 @@
   -->
 
 <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/xsd/maven-4.0.0.xsd"
+        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/xsd/maven-4.0.0.xsd"
 >
-	<modelVersion>4.0.0</modelVersion>
-	<groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
-	<artifactId>jarWithTestDependency</artifactId>
-	<packaging>pom</packaging>
-	<version>1.0</version>
-	
-	<modules>
-		<module>project1</module>
-		<module>project2</module>
-	</modules>
-	
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
+  <artifactId>jarWithNonTestScopedTestDependency</artifactId>
+  <packaging>pom</packaging>
+  <version>1.0</version>
+
+  <modules>
+    <module>project1</module>
+    <module>project2</module>
+  </modules>
+
 </project>
diff --git a/src/test/resources/jarWithTestDependency/pom.xml b/src/test/resources/jarWithNonTestScopedTestDependency/project1/pom.xml
similarity index 64%
copy from src/test/resources/jarWithTestDependency/pom.xml
copy to src/test/resources/jarWithNonTestScopedTestDependency/project1/pom.xml
index 51d6a1e..8959315 100644
--- a/src/test/resources/jarWithTestDependency/pom.xml
+++ b/src/test/resources/jarWithNonTestScopedTestDependency/project1/pom.xml
@@ -20,19 +20,14 @@
   -->
 
 <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/xsd/maven-4.0.0.xsd"
+        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/xsd/maven-4.0.0.xsd"
 >
-	<modelVersion>4.0.0</modelVersion>
-	<groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
-	<artifactId>jarWithTestDependency</artifactId>
-	<packaging>pom</packaging>
-	<version>1.0</version>
-	
-	<modules>
-		<module>project1</module>
-		<module>project2</module>
-	</modules>
-	
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
+  <artifactId>jarWithNonTestScopedTestDependency1</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+
 </project>
diff --git a/src/test/resources/jarWithNonTestScopedTestDependency/project1/src/main/java/jarWithTestDependency/project1/Project1.java b/src/test/resources/jarWithNonTestScopedTestDependency/project1/src/main/java/jarWithTestDependency/project1/Project1.java
new file mode 100644
index 0000000..4f4572d
--- /dev/null
+++ b/src/test/resources/jarWithNonTestScopedTestDependency/project1/src/main/java/jarWithTestDependency/project1/Project1.java
@@ -0,0 +1,36 @@
+package jarWithTestDependency.project1;
+
+/*
+ * 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.
+ */
+
+/**
+ * 
+ * 
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class Project1
+{
+    // constructors -----------------------------------------------------------
+
+    public Project1()
+    {
+        // no-op
+    }
+}
diff --git a/src/test/resources/jarWithNonTestScopedTestDependency/project2/pom.xml b/src/test/resources/jarWithNonTestScopedTestDependency/project2/pom.xml
new file mode 100644
index 0000000..5a7a1b0
--- /dev/null
+++ b/src/test/resources/jarWithNonTestScopedTestDependency/project2/pom.xml
@@ -0,0 +1,61 @@
+<?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/xsd/maven-4.0.0.xsd"
+>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
+  <artifactId>jarWithNonTestScopedTestDependency2</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0</version>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.3.1</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.shared.dependency-analyzer.tests</groupId>
+      <artifactId>jarWithNonTestScopedTestDependency1</artifactId>
+      <version>1.0</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+    </dependency>
+
+  </dependencies>
+
+</project>
diff --git a/src/test/resources/jarWithNonTestScopedTestDependency/project2/src/test/java/jarWithTestDependency/project2/Project2.java b/src/test/resources/jarWithNonTestScopedTestDependency/project2/src/test/java/jarWithTestDependency/project2/Project2.java
new file mode 100644
index 0000000..e64c057
--- /dev/null
+++ b/src/test/resources/jarWithNonTestScopedTestDependency/project2/src/test/java/jarWithTestDependency/project2/Project2.java
@@ -0,0 +1,43 @@
+package jarWithTestDependency.project2;
+
+/*
+ * 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 jarWithTestDependency.project1.Project1;
+
+/**
+ * 
+ * 
+ * @author <a href="mailto:markhobson@gmail.com">Mark Hobson</a>
+ * @version $Id$
+ */
+public class Project2
+{
+    // using a constant from JUnit requires junit dependency but is not detected since the constant
+    // value is copied, then nothing can be detected in bytecode
+    // Not the case any more, since we sniff it from the constant pool
+    public final static int STATUS_ERROR = junit.runner.TestRunListener.STATUS_ERROR;
+
+    // constructors -----------------------------------------------------------
+
+    public Project2()
+    {
+        Project1 project = new Project1();
+    }
+}
diff --git a/src/test/resources/jarWithTestDependency/pom.xml b/src/test/resources/jarWithTestDependency/pom.xml
index 51d6a1e..0db7156 100644
--- a/src/test/resources/jarWithTestDependency/pom.xml
+++ b/src/test/resources/jarWithTestDependency/pom.xml
@@ -29,10 +29,10 @@
 	<artifactId>jarWithTestDependency</artifactId>
 	<packaging>pom</packaging>
 	<version>1.0</version>
-	
+
 	<modules>
 		<module>project1</module>
 		<module>project2</module>
 	</modules>
-	
+
 </project>