Question: I have just upgraded my Gradle to 5.x and I'm having a new error when I try to sync my library project. This error is coming from a publishing block that I need to publish my library to maven local.

This is what I used to do with Gradle 4 and it worked just fine :

```
apply plugin: 'maven-publish'
publishing {
    publications {
        library(MavenPublication) {
            groupId = 'myGroupId'
            artifactId = 'myArtifactId'
            version = android.defaultConfig.versionName

            artifact bundleDebugAar
        }
    }
}

```

With Gradle 5, I now have an error about the artifact when I sync the gradle project:

> 
> ERROR: Could not get unknown property 'bundleDebugAar' for object of
>  type
>  org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.
> 
> 
> 

When I remove the artifact line, I can sync the project but when I'm trying to publishToMavenLocal my build is failing :

> 
> Execution failed for task
>  ':mypackage:generatePomFileForLibraryPublication'.
> 
> 
> 
> > 
> > No value has been specified for this provider.
> > 
> > 
> > 
> 
> 
> 

I looked in the gradle upgrading guide but I don't know how to solve my issue: <https://docs.gradle.org/5.0/userguide/upgrading_version_4.html#rel5.0:pom_compile_runtime_separation>

Can anybody tell me what's changed in this new version that I'm not seeing please ? Thanks.

Answer: 
With gradle 4.8+ you have to enclose the `publishing{}` block inside a `project.afterEvaluate`

```
project.afterEvaluate {
    publishing {
        publications {
            aar(MavenPublication) {
                //...
                artifact bundleReleaseAar
            }
        }
    }
}

```

You can find the [official doc here](https://docs.gradle.org/current/userguide/upgrading_version_4.html#rel4.8:deferred_configuration):

> 
> Prior to Gradle 4.8, the publishing {} block was implicitly treated as if all the logic inside it was executed after the project was evaluated. This was confusing, because it was the only block that behaved that way. As part of the stabilization effort in Gradle 4.8, we are deprecating this behavior and asking all users to migrate their build.
> 
> 
>
You need at least gradle tools dependency `3.6.4`

```
 classpath 'com.android.tools.build:gradle:3.6.4'

```

I was using 3.5.4 which caused that exception