Late version overriding breaks maven-publish plugin configuration

I created demonstration project:

If version from is redefined by Gradle plugin inside project.afterEvaluate:

class AlterVer implements Plugin<Project> {
    void apply(Project project) {
        def extension = project.extensions.create('alterVer', AlterVerExtension)
        project.afterEvaluate {
            project.version = extension.version;

then maven-publish plugin fails to find .jar inside build/libs :

* What went wrong:
Execution failed for task ':publishJarPublicationToBuildRepository'.
> Failed to publish publication 'jar' to repository 'build'
   > Invalid publication 'jar': artifact file does not exist:

Here 0.8 is inside and plugin redefines version to 0.2 :

$ ls build/libs

To run into issue:

$ gradle publishJarPublicationToBuildRepository

I don’t know how to redesign plugin allowing customization of version / group / archive name so that it would work with maven-publish.


I am working on project where custom plugin overrides Project.version (each WSDL endpoint is a separate module with its own versioning).

They use (which sources build.gradle and looks for artifacts much later, so it sees artifacts with updated Project.version).

I ported build to use maven-publish plugin (tested with Gradle 4.6) and I got:

artifact file does not exist


Cannot configure the 'publishing' extension after it has been accessed.

depending how I hacked build.gradle and buildSrc plugin.

maven-publish plugin fixates path during configuration:

publishing.publications {
    jar(MavenPublication) {

instead of doing this lazily.