Late version overriding breaks maven-publish plugin configuration

I created demonstration project:

If version from gradle.properties 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:
     'C:\home\tmp\gradle-alter-version\build\libs\gradle-alter-version-0.8.jar'

Here 0.8 is inside gradle.properties and plugin redefines version to 0.2 :

$ ls build/libs
gradle-alter-version-0.2.jar

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.

TL/DR

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

They use https://www.jfrog.com/confluence/display/RTF/Jenkins+Artifactory+Plug-in (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

or:

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) {
        from project.components.java
    }
}

instead of doing this lazily.