Gradle gets unexpected token, compile files

这一生的挚爱 提交于 2019-12-18 09:34:58

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/33632014/gradle-gets-unexpected-token-compile-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!