Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error in build.gradle.kts on Gradle 7.6 #686

Closed
nipafx opened this issue Nov 14, 2022 · 6 comments · Fixed by #687
Closed

Fix compile error in build.gradle.kts on Gradle 7.6 #686

nipafx opened this issue Nov 14, 2022 · 6 comments · Fixed by #687

Comments

@nipafx
Copy link
Member

nipafx commented Nov 14, 2022

The build file (build.gradle.kts) does not compile on Gradle 7.6-rc-3:

  Line 300: implementation(project)
	^ None of the following functions can be called with the arguments supplied: 
	    public operator fun DependencyAdder.invoke(dependencyNotation: CharSequence): Unit defined in org.gradle.kotlin.dsl
	    public operator fun DependencyAdder.invoke(dependency: Dependency): Unit defined in org.gradle.kotlin.dsl
	    public operator fun DependencyAdder.invoke(files: FileCollection): Unit defined in org.gradle.kotlin.dsl
	    public operator fun DependencyAdder.invoke(dependency: Provider<out Dependency>): Unit defined in org.gradle.kotlin.dsl
	    public operator fun DependencyAdder.invoke(externalModule: ProviderConvertible<out MinimalExternalModuleDependency>): Unit defined in org.gradle.kotlin.dsl

1 error

See, e.g., this build.

@nipafx
Copy link
Member Author

nipafx commented Nov 14, 2022

Investigating the versions, it looks like for a while even the experimental build only used Gradle 7.5.1 (i.e. a released version) and there it worked. The first failure I could find is on 7.6-rc-2. There seems to be no build with 7.6-rc-1.

On 7.5 this worked:

val demoTests by registering(JvmTestSuite::class) {
	dependencies {
		implementation(project)
		implementation("com.google.jimfs:jimfs:1.2")
		implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
		implementation("org.assertj:assertj-core:3.22.0")
	}
	// ...
}

The issue is that JvmComponentDependencies.implementation(Object dependencyNotation), which was called for implementation(project), now indirects via DependencyAdder, which doesn't accept just the project itself. I struggle to find another way to encode the dependency on the main source tree, though.

carterkozak added a commit to carterkozak/junit-pioneer that referenced this issue Nov 14, 2022
@melix
Copy link

melix commented Nov 14, 2022

You should be able to use implementation(project(":junit-pioneer")) instead (if :junit-pioneer is the path of the current project, if I got it correctly).

@carterkozak
Copy link
Contributor

I've pushed #687 which provides more standard syntax (with the caveat that I don't have experience with Kotlin, but it's what I'd do in groovy!)

@jvandort
Copy link

While you cannot use project directly as a dependency, you can use the new syntax implementation(project()). The project() method is provided by Dependencies, an interface which JvmComponentDependencies implements, and returns a ProjectDependency for your current project.

@nipafx
Copy link
Member Author

nipafx commented Nov 15, 2022

Thank you @carterkozak! 🙏🏾 I just pulled main to apply your proposal as given on Mastodon and was surprised to already see it in action. Very cool!

@jvandort That looks like the cleaner syntax but it only works on Gradle 7.6, not on 7.5 yet and we need to build on both. (Because the "real" builds run with 7.5 and experimental ones with 7.6 to preview problems like these.) We can switch to the cleaner project() as soon as we rely on 7.6. 👍🏾

@xuanswe
Copy link

xuanswe commented Jan 8, 2023

Using project() in gradle 7.6, I get error:

* Where:
Build file 'C:\Workspace\Projects\private\Homeschool\parent-tools\parent-tools-api\build.gradle.kts' line: 112

* What went wrong:
Script compilation error:

  Line 112:         implementation(project())
                                   ^ None of the following functions can be called with the arguments supplied: 
                                       public abstract fun project(p0: String!): Project! defined in org.gradle.api.Project
                                       public abstract fun project(p0: String!, p1: Closure<(raw) Any!>!): Project! defined in org.gradle.api.Project
                                       public abstract fun project(p0: String!, p1: Action<in Project!>!): Project! defined in org.gradle.api.Project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants