I have 2 projects in GitHub, project A and project B. I have published artifacts via ./gradlew publish from project A to GitHub and I can see them in https://github.com/my-org/project-a/packages. I am referencing artifacts from project A in the project B, and I am able to successfully build project B on the local machine.
However, when deploying project B via GH Actions, the build fails complaining it can't find the artifacts from project A.
Execution failed for task ':***-api-models:compileKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':***-api-models:compileKotlin'
> Could not resolve all files for configuration ':***-api-models:compileClasspath'.
> Could not find my.org.project-a:project-a-api-models:1.0.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/my/org/project-a/project-a-api-models/1.0.0/project-a-api-models-1.0.0.pom
- file:/root/.m2/repository/my/org/project-a/project-a-api-models/1.0.0/project-a-api-models-1.0.0.pom
- https://maven.pkg.github.com/my-org/***/my/org/project-a/project-a-api-models/1.0.0/project-a-api-models-1.0.0.pom
Here is how I published the artifacts of project A.
project A build.gradle
repositories {
mavenLocal()
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/my-org/project-a")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
publishing {
publications {
gpr(MavenPublication) {
from(components.java)
}
}
repositories {
mavenLocal()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/my-org/project-a")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_USERNAME")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
Here is how I'm reading the artifacts of project A in project B.
project B build.gradle
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
google()
}
dependencies {
implementation "my.org.project-a:project-a-api-models:1.0.0"
The Question
How come that the packages are there in GitHub (I can see them), and I am able to download them to my local machine, but the GH Action from another project somehow does not see them?
Related
I have one Monorepo of Gradle Project and have the below structure with 1 gradle application archive-api and 1 gradle library transcript-xml-parser.
I want to add transcript-xml-parser library dependency into archive-api application. Can anyone suggest how to do that?
Below is my build.gradle file for transcript-xml-parser gradle library:
plugins {
id("java")
}
dependencies {
implementation("javax.xml.bind:jaxb-api:2.3.1")
implementation("org.codehaus.woodstox:stax2-api:4.2.1")
}
repositories {
gradlePluginPortal()
maven {
name "<artifactory-name>"
url "<jfrog-repository-url>"
credentials {
username = username
password = password
}
}
}
I am running into problems with gradle while resolving dependencies. Some of my projects uses a core-lib which I provide by my private repository - nexus3. And the weirdest part is, one of this projects resolves the dependency, while the others can't. I have no Idea what I am doing wrong:
This is how I define my gradle repositories:
repositories {
maven {
credentials {
username = "user"
password = "password"
}
url = uri("https://my-nexus-url/repository/group-repo/")
}
mavenCentral()
}
This is how the dependency is implemented:
dependencies {
...
implementation("my.lib.core:core:1.0")
...
}
This is how is the puiblishing configure block:
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "my.lib.core"
artifactId = "core"
version = "1.0"
from(components["java"])
}
}
repositories {
maven {
credentials {
username = "user"
password = "password"
}
url = uri("https://my-nexus-url/repository/release-repo/")
}
}
}
I am also able to download the artifact via nexus web ui and curl. Furthermore already one of these projects is able to implement it. The rest of them throws:
Could not resolve my.lib.core:core:1.0.
Required by:
project :lib
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Running gradlew ass --refresh-dependencies works fine and ends with:
Cached resource https://my-nexus-url/repository/group-repo/my/lib/core/core/1.0/core-1.0.jar is up-to-date (lastModified: Tue Mar 08 23:05:19 CET 2022).
I'm trying to publish a project with multiple modules to artifactory (oss.jfrog.org). When I run artifactoryPublish I get a 403 error but I know it's not a permissions issue because it works with a single module. It only fails trying publish multiple modules.
Some modules are aars and others are jars and all include sources. I can publish them all to Bintray, but can't publish to artifactory (for snapshots).
So the question is, how do I configure a multi-module project to publish snapshots to oss.jfrog.org.
I've figured out that if I change it to publish a single module and make the artifact name the same as the last part of the group, it works, but a different name doesn't work (gives 403 error).
So if group is com.example.foo I can publish foo.jar (com/example/foo/foo/1.0.0-SNAPSHOT/foo-1.0.0.jar). But I can't publish bar.jar (com/example/foo/bar/1.0.0-SNAPSHOT/bar.jar).
This gradle is included in every project's build.gradle
afterEvaluate {
publishing {
publications {
mavenPublication(MavenPublication) {
artifact sourcesJar
if (project.plugins.hasPlugin("com.android.library")) {
artifact("$buildDir/outputs/aar/${project.name}-debug.aar")
} else {
artifact("$buildDir/libs/${project.name}-${version}.jar")
}
groupId "com.example.foo"
artifactId project.name // changing this to "foo" works for a single project
version version
pom {
name.set(project.name)
url.set(POM_URL)
packaging POM_PACKAGING
version version
licenses {
license {
name.set(POM_LICENSE_NAME)
url.set(POM_LICENSE_URL)
}
}
developers {
developer {
name.set(POM_DEVELOPER)
}
}
scm {
url.set(POM_SCM_URL)
connection.set(POM_SCM_CONNECTION)
developerConnection.set(POM_SCM_DEV_CONNECTION)
}
}
}
}
}
bintray {
user = project.findProperty('bintrayUser') ?: System.getenv('BINTRAY_USER')
key = project.findProperty('bintrayApiKey') ?: System.getenv('BINTRAY_API_KEY')
configurations = ['archives']
publish = true
dryRun = true
pkg {
name = project.name
repo = BINTRAY_REPO
userOrg = BINTRAY_ORG
licenses = [POM_LICENSE_NAME]
vcsUrl = POM_SCM_URL
version {
name = project.name
released = new Date()
}
}
}
artifactory {
contextUrl = 'http://oss.jfrog.org'
publish {
repository {
repoKey = 'oss-snapshot-local'
username = project.findProperty('bintrayUser') ?: System.getenv('BINTRAY_USER')
password = project.findProperty('bintrayApiKey') ?: System.getenv('BINTRAY_API_KEY')
}
defaults {
publications('mavenPublication')
publishArtifacts = true
publishPom = true
}
}
resolve {
repoKey = 'jcenter'
}
}
}
Artifactory returns a 403 whenever you're trying to publish an artefact that already exists. In your case, if you've previously published snapshot artefacts from your multi module build, whenever you will try doing that again, you will get a 403. I know you can configure the user access to provide delete permissions to the account you are using to deploy, as indicated here. However, overwriting history is not considered a good practice.
Regarding renaming your groups and artefacts, I don't think that will provide a solution, as it's not your GAV coordinates that are the issue, but rather the fact that artefacts with matching GAV already exist.
If I may ask, why do you want to use SNAPSHOT artefacts? Can you not achieve the same behaviour with dynamic dependencies and dependency locking?
I want to publish a zip archive to a remote maven repository. The task zipSources packs a sample file into a zip archive. The publication myPubliction publishes to mavenLocal and to the remote maven repository.
The publication works - I can see the packages uploaded to the remote repository. But the build still fails with
> Task :publishMyPublicationPublicationToMavenRepository FAILED
Task ':publishMyPublicationPublicationToMavenRepository' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Publishing to repository 'maven' (null)
FAILURE: Build failed with an exception.
What am I missing? How do I declare outputs for the publishing action? Or is there another cause?
Here is my build.gradle:
plugins {
id "maven-publish"
}
group = 'com.example.test'
version = '0.0.1-SNAPSHOT'
task zipSources(type: Zip, group: "Archive", description: "Archives source in a zip file") {
from ("src") {
include "myfile.txt"
}
into "dest"
baseName = "helloworld-demo"
destinationDir = file("zips")
}
publishing {
publications {
myPublication(MavenPublication) {
artifactId = 'my-library'
artifact zipSources
pom {
name = 'My Library'
description = 'A concise description of my library'
}
}
}
repositories {
maven {
mavenLocal()
}
maven {
url "http://nexus.local/content/repositories/snapshots"
credentials {
username = 'admin'
password = 'admin'
}
}
}
}
It appears there must not be a mavenLocal() declaration inside repositories, as per https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:install
I'm trying to upload a simple zip to artifactory using gradle. This is my script:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
def user = "$System.env.ARTIFACTORY_USER"
def pass = "$System.env.ARTIFACTORY_PASSWORD"
task createArchive(type: Zip){
baseName 'myzip'
destinationDir(new File('target'))
from '.'
exclude 'target'
exclude '.gradle'
exclude 'build.gradle'
exclude 'README.md'
doFirst{
new File('target').mkdirs()
}
}
task clean(type: Delete){
delete 'target'
}
publishing {
publications {
customArtifact(MavenPublication) {
artifact createArchive
}
}
}
artifactory {
publish {
contextUrl = 'http://myrepo/artifactory'
repository {
repoKey = "myrepo-tools"
username = user
password = pass
}
publications ('customArtifact')
}
}
The code seems to work fine but actually only the build info are published. The zip is not:
Deploying build descriptor to: http://myrepo/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://myrepo/artifactory/webapp/builds/myproject/1503338121156
My code does not seem different from the one published here: How to build Groovy JAR w/ Gradle and publish it to in-house repo (which was pointed as reference in question nothing published to artifactory using gradle artifactory plugin) but I'm not sure that is still valid since is quite old.
The main difference is that almost all the examples are using java plugin so they have the from components.java line in the publications. In my case I cannot use it as I have a custom zip.. but I can't find what else can be changed.
Thanks,
Michele.