Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.springframework.test cannot be resolved also with maven dependency present

I'm having an issue while trying to build test suites for my Spring application. I'm new to Maven and I can't find what is wrong. I've added to my pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>3.0.0.RELEASE</version>
    <scope>test</scope> 
</dependency>

but I'm still getting from Eclipse the error: The import org.springframework.test cannot be resolved.

Following this discussion ( http://appfuse.547863.n4.nabble.com/spring-test-package-not-found-td1596479.html ), I tried to add <scope>provided<scope> without success.

Here is my complete pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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.mose</groupId>
<artifactId>emergency-alert-server</artifactId>
<name>emergency-alert-server</name>
<version>1.0.0-BUILD-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.0.5.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.10</org.aspectj-version>
    <org.slf4j-version>1.6.1</org.slf4j-version>
</properties>
<dependencies>
    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
        <exclusions>
            <!-- Exclude Commons Logging in favor of SLF4j -->
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
             </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>

    <!-- AspectJ -->
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>${org.aspectj-version}</version>
    </dependency>   

    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${org.slf4j-version}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>runtime</scope>
    </dependency>

    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- Jackson JSON Processor -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.7.6</version>
    </dependency>

    <!-- JAXB XML Processor -->
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.2</version>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- File Upload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</version>
    </dependency>

    <!-- Test-->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency> 
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>3.0.0.RELEASE</version>
        <scope>test</scope> 
    </dependency>
    <dependency>
        <groupId>hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>1.8.0.10</version>
        <type>jar</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.2.2</version>
        <scope>test</scope>
    </dependency>

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>   
    <!-- Hibernate framework -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>3.6.0.Final</version>
    </dependency>
    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
    <!-- Google Cloud Messaging for server  -->
    <dependency>
        <groupId>com.google.android.gcm</groupId>
        <artifactId>gcm-server</artifactId>
        <version>1.0.2</version>
    </dependency>
</dependencies>

<repositories>
    <!-- For testing against latest Spring snapshots -->
    <repository>
        <id>org.springframework.maven.snapshot</id>
        <name>Spring Maven Snapshot Repository</name>
        <url>http://maven.springframework.org/snapshot</url>
        <releases><enabled>false</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <!-- For developing against latest Spring milestones -->
    <repository>
        <id>org.springframework.maven.milestone</id>
        <name>Spring Maven Milestone Repository</name>
        <url>http://maven.springframework.org/milestone</url>
        <snapshots><enabled>false</enabled></snapshots>
    </repository>
    <!-- For Spring releases -->
    <repository>
        <id>org.springframework.maven.release</id>
        <name>Spring Maven Release Repository</name>
        <url>http://maven.springframework.org/release</url>
        <snapshots><enabled>false</enabled></snapshots>         
    </repository>
    <repository>
      <id>repository.jboss.org-public</id>
      <name>JBoss repository</name>
      <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
    <repository>
        <id>gcm-server-repository</id>
         <url>https://raw.github.com/slorber/gcm-server-repository/master/releases/</url>
    </repository>       
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>apache.snapshots</id>
        <name>Apache Snapshots</name>
        <url>http://people.apache.org/repo/m2-snapshot-repository</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>                
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>sources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <!-- Have to use version 1.2 since version 1.3 does not appear to work with ITDs -->
            <version>1.2</version>
            <dependencies>
                <!-- You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) -->
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>${org.aspectj-version}</version>
                </dependency>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>${org.aspectj-version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <outxml>true</outxml>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.0-SNAPSHOT</version>
            <!-- 
            <configuration>
                <contextFile>src/main/webapp/META-INF/context.xml</contextFile>
            </configuration> -->
            <dependencies>      
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.9</version>
                </dependency>
            </dependencies>
        </plugin>                       
    </plugins>
</build>

Then I tried to run mvn dependency:tree, but i can't see nothing strange:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building emergency-alert-server 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ emergency-alert-server ---
[INFO] org.mose:emergency-alert-server:war:1.0.0-BUILD-SNAPSHOT
[INFO] +- org.springframework:spring-orm:jar:3.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.5.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-asm:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:3.0.5.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-tx:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-tx:jar:3.0.5.RELEASE:compile
[INFO] |     +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |     +- (org.springframework:spring-aop:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-context:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-context:jar:3.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
[INFO] |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-asm:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-expression:jar:3.0.5.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.5.RELEASE:compile
[INFO] |  +- (org.springframework:spring-asm:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-context:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-context-support:jar:3.0.5.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-context:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-expression:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-web:jar:3.0.5.RELEASE:compile
[INFO] |     +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-context:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:3.0.5.RELEASE:compile - omitted for duplicate)
[INFO] +- org.aspectj:aspectjrt:jar:1.6.10:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.6.1:runtime
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.1:runtime - omitted for duplicate)
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.1:runtime
[INFO] |  +- (org.slf4j:slf4j-api:jar:1.6.1:runtime - omitted for duplicate)
[INFO] |  \- (log4j:log4j:jar:1.2.16:runtime - omitted for duplicate)
[INFO] +- log4j:log4j:jar:1.2.16:runtime
[INFO] +- javax.inject:javax.inject:jar:1:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.7.6:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.7.6:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.2.2:compile
[INFO] +- commons-io:commons-io:jar:1.4:compile
[INFO] +- junit:junit:jar:4.7:test
[INFO] +- org.springframework:spring-test:jar:3.0.0.RELEASE:test
[INFO] +- hsqldb:hsqldb:jar:1.8.0.10:test
[INFO] +- commons-dbcp:commons-dbcp:jar:1.2.2:test
[INFO] |  \- commons-pool:commons-pool:jar:1.3:test
[INFO] +- mysql:mysql-connector-java:jar:5.1.9:compile
[INFO] +- org.hibernate:hibernate-core:jar:3.6.0.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] |  |  \- (org.slf4j:slf4j-api:jar:1.5.8:compile - omitted for conflict with 1.6.1)
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO] |  +- javax.transaction:jta:jar:1.1:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for duplicate)
[INFO] +- javassist:javassist:jar:3.12.1.GA:compile
[INFO] \- com.google.android.gcm:gcm-server:jar:1.0.2:compile
[INFO]    \- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.642s
[INFO] Finished at: Sat Nov 10 11:44:19 CET 2012
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------  

Any help would be appreciated, thanks in advance.

like image 752
user1781028 Avatar asked Nov 10 '12 10:11

user1781028


2 Answers

If the Maven build succeeds but Eclipse sees errors, it indicates that Eclipse is not reading the same jars as Maven is importing. Right-click the project and select Maven/update and follow this by a Project/clean.

Sometimes the Eclipse (Kepler) Maven plugin fails to download a jar. Check that the missing jar is in your local repository. Often there will just be some files that tell Maven not to attempt another download for a fixed time. If so, delete the repository section for that jar, temporarily set the scope to compile, and do a Maven clean and install. If that does not work, open a command window in the directory of the pom.xml file, and issue a mvn -U clean install command.

Also, your pom.xml looks rather large to me. It is good practice to put common stuff like repository definitions, compiler versions etc int a parent pom that can be shared by all the components of your project. I like to rely on transitive dependencies (e.g. spring-mvc will probably suck in the rest of the Spring framework without you specifying it).

like image 84
kiwiron Avatar answered Nov 15 '22 21:11

kiwiron


The package org.springframework.transaction is provided by the spring-tx artifact, not spring-test.

You will probably get away by adding this to your pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${org.springframework-version}</version>
</dependency>
like image 36
Samuel Rossille Avatar answered Nov 15 '22 21:11

Samuel Rossille