Cannot resolve dependencies (Maven and Gradle) with Google Artifacts Registry - google-artifact-registry

I'm facing problem with artifact registry
I use Gradle, I can publish a jar
But I cannot download dependency
I try also with Maven, same thing, I can publish but not download
There are very few informations on internet and no support
I run
gcloud auth application-default login
I'm connected to GCP
I copy paste the code from the interface : https://console.cloud.google.com/artifacts/maven/mmnb-299822/us-east1/maven?hl=fr&project=abc-123
plugins {
id "maven-publish"
id "com.google.cloud.artifactregistry.gradle-plugin" version "2.1.1"
}
publishing {
repositories {
maven {
url "artifactregistry://us-east1-maven.pkg.dev/abc-a123/maven"
}
}
}
repositories {
maven {
url "artifactregistry://us-east1-maven.pkg.dev/abc-a123/maven"
}
}
Thank you for help

Here is a template on how you can download dependencies on Maven.
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1.0</version>
</dependency>
<dependencies>
And here is the template for Gradle:
dependencies {
compile group: 'group', name: 'artifact', version: '1.0'
}
You must also consider that this is in Alpha stage and can have limited support. To get more information about this topic, please visit the official documentation page for Managing Packages for AR.

Related

Missing artifact in vaadin start project (maven issue)

I was just about to get started with the vaadin start project (https://start.vaadin.com/). I downloaded it and imported it into eclipse. However after that I got a Maven import error on line 112+ telling me there is a "Missing artifact org.vaadin.artur:a-vaadin-helper:jar:1.5.0"
<dependency>
<groupId>org.vaadin.artur</groupId>
<artifactId>a-vaadin-helper</artifactId>
<version>1.5.0</version>
</dependency>
All other dependencies can be resolved. I do not have a custom settings.xml for maven. Refreshing does not help.
The artifact is located in the Vaadin Addons repository (for which there is a definition in the pom.xml). Perhaps you are using a Maven proxy that does not include this repository?

Cannot download sources from jar in intellij with maven

I want to debug my maven project. I add a dependency Test that I have developped like this:
<dependencies>
<dependency>
<groupId>com.company.group</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
when I debug my program and I enter into Test dependent method I see /* compiled code */. If I click on attach source It does nothing and if I click on download source, I get a pop up message saying:
Cannot download sources,
Sources not found for:
com.mycompany.group:test:0.0.1-SNAPSHOT
I also tried to execute :
mvn dependency:sources
But when I try to enter my dependent method I just see /* compiled code */
Do you have any idea?
It's not uncommon for sources to be unavailable for custom jars, since developers would have to explicitly create a source jar using the Maven Source
Plugin and install this jar in a remote repository. There's a Maven cookbook page for this as well.
If you have no way of adding sources for your dependencies, then I think your best bet would be to use a decompiler.

Spring MVC with Spring Boot doesn't work with the Tomcat server of Eclipse

I tried to follow Spring Getting Started Guide for "Serving Web Content with Spring MVC" which uses Spring Boot and Gradle in addition to Maven.
I installed Gradle plugins to Eclipse.
I want to run the application using the Tomcat server in Eclipse because of that I also followed "Converting a Spring Boot JAR Application to a WAR" guide and changed the "build.gradle" file as mentioned in the guide. Basically, I added lines "apply plugin: 'eclipse-wtp'", "apply plugin: 'war'", configurations {providedRuntime}, and providedRuntime("org.springframework.boot:spring-boot-starter-tomcat"); and changed jar settings to war settings. Here is the build.gradle file:
buildscript {
repositories {
maven { url "http://repo.spring.io/libs-milestone" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.2.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
eclipse.project {
natures 'org.springsource.ide.eclipse.gradle.core.nature'
}
war {
baseName = 'gs-serving-web-content'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
testCompile("junit:junit")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
I also added HelloWebXml class as they mention. Here is the class:
package hello;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class HelloWebXml extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
In addition to these I needed to change pom.xml a little because it was complaining about Java SE 7 features. Added the lines below to the pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showWarnings>true</showWarnings>
<compilerVersion>1.7</compilerVersion>
<fork>true</fork>
</configuration>
</plugin>
The rest is the same as the getting started guide.
For building, I run
gradlew eclipseWtp
gradlew clean build
commands. After this the war file is created in build/libs folder of the project. If I copy the war file to my local Tomcat server and start the server, everything works as expected.
If I drag the project to the Tomcat server under the Servers tab (which is created using the same local Tomcat) and run the server, a ClassCastException is thrown with the complaint:
"Cannot cast org.springframework.web.SpringServletContainerInitializer to javax.servlet.ServletContainerInitializer".
I checked the folder structure of the project in both of the deployment locations.
In the local (non-Eclipse) deployment location, after the server starts a folder with the name of the war file is created as expected. In the WEB-INF folder, there is a lib-provided directory. I checked the deployment location of the Tomcat of Eclipse, it didn't include a directory named lib-provided. I guess the problem is about this directory not being created but I couldn't find a solution.
I was already using Spring MVC, and I know how to create MVC projects with web.xml but I am new to Spring Boot. The Tomcat server of Eclipse runs my previous Spring MVC projects fine. So the problem is about the Spring Boot project.
I checked several related questions but they were not the same one as mine. I couldn't find a solution to my problem.
What am I missing here?
Thanks in advance.
I imagine that you are getting a clash with the servlet-api JARs. If you are developing with embedded Tomcat (creating a JAR) you need to include the servlet-api JAR on your classpath in the compile scope. When you are deploying to an existing Tomcat installation (creating a WAR) you must declare the servlet-api jar in provided scope, otherwise it will end up in web-inf/lib and cause conflicts with the version provided by your container.
Here is the POM from the sample Spring Boot WAR project:
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-traditional/pom.xml
Note how the spring-boot-starter-tomcat uses the provided scope.
Spring Boot does some special handling to allow executable WARs that run both embedded or in a container. Specific attention has to be payed to dependencies in provided scope since these might conflict with the container. The details are described in the Spring Boot reference guide. The reason your build works when deployed via a built WAR but not via Eclipse is that Eclipse WTP doesn't actually use Maven to perform the build, so a Maven build and a WTP build won't exactly match.
I'm working on addressing the same issue myself. What I plan to do is create a seperate 'dev' maven module specifically for this purpose, and use tags to switch (some of) the provided entries to runtime.
#meribald you can configure your pom.xml in that whay:
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<packaging-profile>jar</packaging-profile>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<properties>
<packaging-profile>war</packaging-profile>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>
and on the top of your pom.xml
<packaging>${packaging-profile}</packaging>
So, when you are developing you run you application as a Java Application, and maven will generate a jar file. When you want to package a war file to deploy on a server, you run on a maven command line
mvn -Pprod package
or in Eclipse run as >> Maven Build ..., and put "package" on the goals field, and "prod" (without quotes) on profiles field.

Maven dependency based on Eclipse Target Platform - Plug-in Development

While developing a plugin for eclipse 3.7.2 I have a dependency on refactoring.jar which will be part of the Target Platform - Plug-in Development. If the target platform changes, the version of the jar might change. As this specific version is not available on maven central repo nor any of our internal repos, I copied the jar to the project/lib dir and defined in pom.xml with dependency systemPath as the following.
<dependency>
<groupId>org.eclipse.ltk.core</groupId>
<artifactId>refactoring</artifactId>
<version>3.5.201-r372_v20111101-0700</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/refactoring-3.5.201-r372_v20111101-0700.jar</systemPath>
</dependency>
It compiles the project and runs successfully on the target platform. But I would like to make the dependency independent of the version/target platform. Means it should always pickup the target platform version. Appreciate any suggestions on this.
By using dependency management this is some how simplified with changes in one place.
-----In paretn pom --------
`<dependencyManagement>
<dependency>
<groupId>org.eclipse.ltk.core</groupId>
<artifactId>refactoring</artifactId>
<version>3.5.201-r372</version>
</dependency>
</dependencyManagement>`
------In individal pom files -----------
`<dependency>
<groupId>org.eclipse.ltk.core</groupId>
<artifactId>refactoring</artifactId>
<scope>provided</scope>
</dependency>`

eclipse cannot find the jar available in maven dependencies

I have a pom.xml with the following entry
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
And on maven install the jar is added to the maven repository and is also listed in the maven dependencies library.
But I am not able to import any of the classes from the added jar 'spring-web-3.1.0.RELEASE.jar' for the particular entry, though it shows in the classpath
The error - in eclipse "cannot be resolved to a type"
environment - maven 3.1 and Spring tool suite
Thanks
Solved - found the solution through some other forum
The jar inside the repository was corrupted.
After clearing the .m2 folder in the physical drive and repeating the maven clean install worked.
Thanks for the time #techidiot #jtravaglini.