Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: Could not find method providedCompile()

How are this and this build file able to use providedCompile?

thufir@doge:~/NetBeansProjects/gradleEAR$  thufir@doge:~/NetBeansProjects/gradleEAR$ gradle clean  FAILURE: Build failed with an exception.  * Where: Build file '/home/thufir/NetBeansProjects/gradleEAR/build.gradle' line: 40  * What went wrong: A problem occurred evaluating root project 'gradleEAR'. > Could not find method providedCompile() for arguments [javax:javaee-api:7.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.  * 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: 12.721 secs thufir@doge:~/NetBeansProjects/gradleEAR$   plugins {     id 'com.gradle.build-scan' version '1.8'      id 'java'     id 'application'     id 'ear' }  mainClassName = 'net.bounceme.doge.json.Main'  buildScan {     licenseAgreementUrl = 'https://gradle.com/terms-of-service'     licenseAgree = 'yes' }  repositories {     jcenter() }  jar {     manifest {         attributes 'Main-Class': 'net.bounceme.doge.json.Main'     } }  task fatJar(type: Jar) {     baseName = project.name + '-all'     from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }     with jar     manifest {         attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': '3.4.0'         attributes 'Main-Class': 'net.bounceme.doge.json.Main'     } }  dependencies {     compile group: 'javax.json', name: 'javax.json-api', version: '1.1'     compile group: 'org.glassfish', name: 'javax.json', version: '1.1'     providedCompile 'javax:javaee-api:7.0' } 

In reference to:

How does Gradle resolve the javaee-api dependency to build an EAR?

like image 508
Thufir Avatar asked Aug 22 '17 04:08

Thufir


People also ask

What is providedCompile in gradle?

providedCompile is also a configuration in gradle script, which enables any JAR and its transitive dependency not to go in WAR archive but be available at compile time.

What is the difference between compile and implementation in gradle?

Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.


2 Answers

You can get this error if you have a higher version of Gradle installed. For example you have:

gradle --version 

giving

Gradle 5.0 

but the project expects Gradle 2.10 or some other lower version of Gradle.

To solve this first try to use Gradle wrapper ./gradlew (if included with project) instead of locally installed gradle. Or install a correct version of gradle and make it available using path variable.

like image 42
Master Drools Avatar answered Sep 22 '22 04:09

Master Drools


providedCompile is shipped with war plugin. So you need to add:

plugins {   // ...   id 'war' } 
like image 147
Opal Avatar answered Sep 24 '22 04:09

Opal