Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

build.gradle - Gradle gets unexpected token, compile files

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:UserssinghaDocumentsGitHubcoalition-servicesuild.gradle' line: 52

    • What went wrong: Could not compile build file 'C:UserssinghaDocumentsGitHubcoalition-servicesuild.gradle'.

      startup failed: build file 'C:UserssinghaDocumentsGitHubcoalition-servicesuild.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:UserssinghaDocumentsGitHubcoalition-servicesuild.gradle'.

    startup failed: build file 'C:UserssinghaDocumentsGitHubcoalition-servicesuild.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...