4

I am looking to add a test dependency to my project which uses gradle. What I simply need is for gradle to download the dependency jar so I can import part of the package. What I need is the following package:

import org.springframework.security.test.*

So I edited my gradle file to contain

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    runtime('org.hsqldb:hsqldb')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test') // This is what I added to try and download the new dependency
}

I tried building the project after entering this. Unfortunately this didn't work and I cannot import org.springframework.security.test.* I then ran gradlew test which actually had some success and showed:

Download https://repo1.maven.org/maven2/org/springframework/security/spring-security-test/4.0.3.RELEASE/spring-security-test-4.0.3.RELEASE.pom
Download https://repo1.maven.org/maven2/org/springframework/security/spring-security-test/4.0.3.RELEASE/spring-security-test-4.0.3.RELEASE.jar 

Though I have no idea where it downloaded to. Navigating to $HOME/.gradle/caches/modules-2/files-2.1/org.springframework.security I can see no sign of the downloaded package (and Idea doesn't recognise it in its external libraries). Running gradle build --refresh-dependencies didn't seem to work.
Any help would be very much appreciated.

Closes SO question I could find

Community
  • 1
  • 1
DWB
  • 1,544
  • 2
  • 16
  • 33
  • 4.04 is the latest version I see in the Maven repository... But I don't see anything wrong with what you have done since it clearly said it was downloaded – OneCricketeer Apr 24 '16 at 21:23
  • What exactly is your question or problem? What do you need the physical location of the downloaded JAR for? – Vampire Apr 24 '16 at 21:29
  • @BjörnKautler It says the dependency downloaded (using `gradlew`) but I cannot find nor use `spring-security-test` – DWB Apr 24 '16 at 21:32
  • You answered none of my questions. What do you need the physical location of the downloaded JAR for and what problem do you have if you use it. How do you use it? What errors do you get? ...? – Vampire Apr 24 '16 at 21:56
  • @BjörnKautler The problem: How do I get gradle to download `org.springframework.security:spring-security-test` so I can `import org.springframework.security.test.*`. I built the project and that didn't work, then I used gradlew to try to download the dependency but as far as I can tell it said it downloaded it but I do not know where. Me looking for the physical jar was me seeing whether gradlew actually downloaded anything to the gradle cache which it did not. I edited the question to be clearer – DWB Apr 24 '16 at 22:03
  • You still do not specify what problem you have if you use it. How do you use it? What errors do you get? Searching for the physical JARs is not your real problem. If you want help, state your real problem. It could well be that the file is not where you expect it. It could e. g. be in your local .m2 repository if it was downloaded earlier and Gradle reused that download and similiar stuff. For the start just trust Gradle that it knows what it does and state your real problem if you want to solve it. This is the last time I ask for it, after that I'll not look at this thread anymore, I'm tired. – Vampire Apr 24 '16 at 22:54
  • 1
    btw. afair --refresh-dependencies just forgets about whether it found what in which repository and looks afresh. So if it didn't find a dep in a specific version in a specific repository it can happen that gradle remembers this and needs --refresh-dependencies to look again in the repository. It has nothing to do with re-downloading dependencies. – Vampire Apr 24 '16 at 22:56

1 Answers1

1

I had the same issue, it works if a specific version is included in the dependency, such as:

testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '5.1.6.RELEASE'