Skip to content
Advertisement

Cannot change dependencies of configuration ‘:compile’ after it has been resolved

I have a simple java project that uses json.jar library. gradle.build file content is:

JavaScript

problem is when I want to add json to my classpath and use it, this error happens

JavaScript

how can I solve this?

Advertisement

Answer

First, you have to add a repositories block to specify where dependencies are retrieved from (usually before dependencies {...}.

JavaScript

Then, if you put the dependencies block before the jar block it seems to work, although I’m not sure about why it doesn’t work the other way (maybe jar {...} uses the compile configuration and “locks” it).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement