Gradle gets unexpected token, compile files
Asked Answered
R

1

3

What am I doing wrong ? I am referring to this

build.gradle

compile files('libs/redisson-1.3.2-SNAPSHOT.jar')

ls libs/

$ ls libs/
redisson-1.3.2-SNAPSHOT.jar

Error

* Where:
Build file '/myfolder/myproject/build.gradle' line: 162

* What went wrong:
Could not compile build file '/myfolder/myproject/build.gradle'.
> startup failed:
  build file '/myfolder/myproject/build.gradle': 162: unexpected token: redisson @ line 162, column 23.
            compile files('libs/redisson-1.3.2-SNAPSHOT.jar')
                           ^

  1 error


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.942 secs
Redmund answered 10/11, 2015 at 14:14 Comment(0)
C
3

I got the same issue and fixed it.

Cause: This issue comes because of unresolved dependency in build.gradle file. It would be more clear by below example: Example: I have given a json-simple dependency in build.gradle file which will result in build error at next line. 1.

compile("com.googlecode.json-simple:json-simple:1.1"
compile("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")

build result:

  • Where: Build file 'C:\Users\singha\Documents\GitHub\coalition-services\build.gradle' line: 52

    • What went wrong: Could not compile build file 'C:\Users\singha\Documents\GitHub\coalition-services\build.gradle'.

      startup failed: build file 'C:\Users\singha\Documents\GitHub\coalition-services\build.gradle': 52: unexpected token: compile @ line 52, column 4. compile("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")

  1. Tried putting the same unresolved dependency at diffrent place in build file

compile("com.googlecode.json-simple:json-simple:1.1" compile files('libs/google-http-client-1.18.0-rc.jar')

result:

  • What went wrong: Could not compile build file 'C:\Users\singha\Documents\GitHub\coalition-services\build.gradle'.

    startup failed: build file 'C:\Users\singha\Documents\GitHub\coalition-services\build.gradle': 68: unexpected token: compile @ line 68, column 2. compile files('libs/google-http-client-1.18.0-rc.jar')

Solution: Just delete the previous line where the given error is coming as that could be causing the issue. In your case, try deleting the 161 line or previous line of dependency given.

Please let me know if it resolved the problem.

Com answered 10/5, 2016 at 16:56 Comment(2)
I'll try it out tomorrow and report back. ThanksRedmund
Awesome answer. Don't look to fix the build.gradle line where the error is reported. Look to fix the line before where the error is reported. In my case it was a missing )Guarani

© 2022 - 2024 — McMap. All rights reserved.