简体   繁体   中英

Gradle unable to publish multiple maven native artifacts

I can't seem to get Gradle to publish multiple artifacts to a Maven repository. It publishes some, but not all, and I have no idea why. The targets are debug & release versions of static libraries, built for OS X and Windows (4 static libraries in total). The OS X libraries are stored but the Windows ones are not. If I modify the filter closure such that the OS X libraries are filtered out, nothing is stored.

model {
  buildTypes {
    debug
    release
  }

  platforms {
    "osx-x86_64" {
        operatingSystem "osx"
        architecture "x86_64"
    }

    "windows-x86_64" {
        operatingSystem "windows"
        architecture "x86_64"
    }
  }

  toolChains {
    // OS X and Windows toolchains (Clang and Mingw) described here
    // - they build the artifacts I wish to store ok
    // just removed for clarity       
  }

}  // end of model

libraries {
    saveMe {}
}

nativeArtifacts {
    libSaveMe {
        from (libraries.saveMe) { it instanceof StaticLibraryBinary && 
            (it.targetPlatform.name == "osx-x86_64" ||
            it.targetPlatform.name == "windows-x86_64")     
        // if I make this closure on the line above something like:
        // it instanceof StaticLibraryBinary && it.targetPlatform.name == "windows-x86_64"
        // then nothing is saved in the Maven repo  
        }
    }
}

publishing {
    repositories {
        maven {
            credentials {
                username = 'user'
                password = 'password'
            }
            url "http://hostname.com/path/to/repo"
        }
    }
    publications {
        mavPub(MavenPublication) {
            from nativeArtifacts.libSaveMe
        }       
    }               
}

I'm using a very nice external plugin ( Gradle Native Artifacts Plugin , written by Serge Gebhardt @sgeb (?)) but before I try to make sense of his code (I'm a beginner in Gradle), I thought I'd ask and see if there's something obvious I'm doing wrong.

I've tried putting logger statements in the filter closure and I can see that all possible combos of debug/release static/shared libraries are being tried, and the filter is correctly identifying true/false whether the libraries should be saved, but it doesn't make it to Maven.

Is there a debugging line I could put in publishing{} (or a task) to see what the actual contents of the nativeArtifacts.libSaveMe collection is?

OK, so the moral of the story is: never assume, check. In this instance, check that the statement:

toolChains {
    // OS X and Windows toolchains (Clang and Mingw) described here
    // - they build the artifacts I wish to store ok
    // just removed for clarity       
  }

is actually true. It wasn't.

The publish task was being done by a CI server and the toolchain was failing to build the windows artifacts on the CI server, but it was working on my local machine (due to a config error in the installation of the mingw toolchain). The toolchain failure was occurring without an error (unless run in --debug) and hence was invisible to me, as the toolchain was being replaced by a non-Windows compiler that didn't create the artifacts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM