Maven Wagon plugin Post - maven

I have some xml files and I want to upload them to my domain. Only way i can do it is through endpoint. I have configured maven wagon plugin like below
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<goals>
<goal>upload</goal>
</goals>
<configuration>
<fromDir>target</fromDir>
<includes>*jssp.xml</includes>
<url> http://mydomain/endpoint?__sessiontoken=admin/admin</url>
</configuration>
</plugin>
And i have this
Failed to execute goal org.codehaus.mojo:wagon-maven-plugin:1.0:upload (default-cli) on project AdobeCampaignUploader: Error handling resource: Access denied to: http://mydomain/endpoint?__sessiontoken=admin/admin/file.xml
How to POST this file to remote location properly?

You are probably missing your authentication here. To ~/.m2/settings.xml, add your http credentials, then use these here in your pom.

Related

Cannot push to remote repo using the (spotify) Docker maven plugin

I've got a Spring Boot project which I want to built an image from and push to a Docker private registry. I've followed Spring Boot official docs for that, using the Spotify Docker Maven plugin. That worked well when publishing my image to a docker local instance using Boot2Docker.
Now I'm trying to do the same with a remote private repo (an unsecured one) and I'm struggling with it. I've followed the plugin documentation for that and that's how my configuration looks like:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.9</version>
<configuration>
<imageName>service-discovery</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.war</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
<execution>
<id>tag-image</id>
<phase>package</phase>
<goals>
<goal>tag</goal>
</goals>
<configuration>
<image>service-discovery</image>
<newName>develop01.mycompany.com:5000/service-discovery</newName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My registry is accessible through http://develop01.mycompany.com:5000, but the docker plugin seems not to be able to find it.
Executing mvn clean install throws:
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.9:build (buil
d-image) on project service-discovery: Exception caught: java.util.concurrent.Ex
ecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingExcepti
on: org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375 [lo
calhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connec
t -> [Help 1]
Executing mvn docker:tag -DpushImage throws:
[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.9:tag (defaul
t-cli) on project service-discovery: The parameters 'image', 'newName' for goal
com.spotify:docker-maven-plugin:0.4.9:tag are missing or invalid -> [Help 1]
So the plugin seems not to recognize the parameters into the image goal (in fact, it looks like it's trying to connect to a local Docker instance when executing mvn clean install).
Software:
docker version: Server: 1.11.0
docker-maven-plugin version: 0.4.9
maven version: 3.2.3
A link to the GitHub issue I created
Update
I have set my DOCKER_HOST environment variable to tcp://develop01.mycompany.com:5000 and now the plugin seems to pick it. Still don't understand why I have to do it through an environment variable, when I'm declaring the server name in the execution configuration. All in all, that's the error I'm getting right now:
[ERROR] Failed to execute goal
com.spotify:docker-maven-plugin:0.4.9:build (buil d-image) on project
service-discovery: Exception caught: Request error: GET http
://develop01.mycompany.com:5000/version: 404: HTTP 404 Not Found ->
[Help 1]
In fact, the /version endpoint of my registry returns 404. The /v2 endpoint however, returns an empty JSON. Is the plugin trying to deal with a previous docker version API?

Using Maven license plugin in multimodule project

I am working on a multi-module projects where all modules share a common licence (Apache 2.0). Now I want to add headers to all source files and I want to configure this in the parent's pom.xml (packaging type is pom)
I created a folder license in the base dir and added a file licenses.properties where I state apache_2_0=apache_2_0. Also, I added a subfolder apache_2_0 where I have two files header.txt and license.txt. Now I added the following plugin to my parent pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<licenseName>apache_2_0</licenseName>
<licenseResolver>${project.basedir}/license</licenseResolver>
</configuration>
<executions>
<execution>
<goals>
<goal>update-file-header</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I run this, I do however get an error message:
[ERROR] Failed to execute goal
org.codehaus.mojo:license-maven-plugin:1.5:update-file-header
(default) on project (myproject): could not obtain the license
repository: unknown protocol: c -> [Help 1]
with the following exception:
java.net.MalformedURLException: unknown protocol: c
What am I doing wrong?
You have not defined any protocole (file://, http://, ...) on your licenseResolver
replace
<licenseResolver>${project.basedir}/license</licenseResolver>
with
<licenseResolver>file://${project.basedir}/license</licenseResolver>
Or simply use ${project.baseUri}

Maven 3 - Distribute custom plugin in a .jar?

Complete Maven newb here, so forgive any abused terminology, etc.
I've built a custom plugin in Maven 3 (one that defines goals for git rebase). I'm able to:
mvn install
No problem. I can then invoke the goal from the command line:
mvn edu.clemson.cs.rsrg:git-plugin:rebase
Everything's golden. I have this lovely git-plugin-XXX.jar file sitting in my target directory.
I'd like to make my custom goals available to another project such that when other members of the dev team pull down that project's source, they get my plugin for free (or at least, after a mvn build).
My understanding is that the purist solution is to set up a maven repo for the group and load my plugin there, but that seems overkill for a single hacky plugin.
Thoughts?
I've played with doing it via three different plugins so far:
addjars-maven-plugin:add-jars
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.4</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/plugins</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Gives me this error during mvn build:
[ERROR] Error resolving version for plugin 'edu.clemson.cs.rsrg:git-plugin' from the repositories [local (/home/hamptos/.m2/repository), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository
It also causes my later formatting plugin to fail. (Clearly it's read the jar and determined the group name/plugin name, but then it goes and looks for it in my local repo? Of course it's not there--I'm trying to install it.)
build-helper:attach-artifacts
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>install</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${basedir}/plugins/git-plugin-0.1.0a.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Gives me this error during mvn build:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) on project RESOLVE: Execution attach-artifacts of goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact failed: For artifact {edu.clemson.cs.rsrg:RESOLVE:12.09.01a:jar}: An attached artifact must have a different ID than its corresponding main artifact.
(RESOLVE:12.09.01a being the main project. Clearly something's gone awry here because the plugin and main project definitely have different artifactIDs. Trying to attach the project on top of itself maybe?)
maven-install-plugin:install-file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install-git-plugin</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/plugins/git-plugin-0.1.0a.jar</file>
<packaging>jar</packaging>
<groupId>edu.clemson.cs.rsrg</groupId>
<artifactId>git-plugin</artifactId>
<version>0.1.0a</version>
</configuration>
</execution>
</executions>
</plugin>
Seems to work fine until I try to invoke one of the goals like mvn edu.clemson.cs.rsrg:git-plugin:rebase, at which point it gives me this error:
[ERROR] Failed to execute goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase (default-cli) on project RESOLVE: Execution default-cli of goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase failed: Unable to load the mojo 'rebase' (or one of its required components) from the plugin 'edu.clemson.cs.rsrg:git-plugin:0.1.0a': com.google.inject.ProvisionException: Guice provision errors:
[ERROR]
[ERROR] 1) Error in ComponentFactory:ant-mojo
[ERROR] at ClassRealm[plugin>edu.clemson.cs.rsrg:git-plugin:0.1.0a, parent: sun.misc.Launcher$AppClassLoader#e776f7]
[ERROR] while locating org.apache.maven.plugin.Mojo annotated with #com.google.inject.name.Named(value=edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase)
You may think it is hacky, but it is the maven way. It needs to be deployed to a maven repo.
If you keep it in a groupId that you can demonstrably own and it's open source you can publish it to central

maven plugin ignored from local pom plugins

I am new to maven, and cannot figure it out.
I have this configuration for the plugin in my pom.xml file, but it looks like mvn does not use my configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
I am getting the same error when I comment out this plugin. There are old discussions on the blogs that maven was ignoring configurations inside the execution. Is it still an issue ? How can I make maven to read my plugin declarations instead of something else? What does it run when my dependency is commented out?
Error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install- plugin:2.3.1:install-file (default-cli) on project core: The parameters 'file' for goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are missing or invalid -> [Help 1]
From the error message and the information above, one possibility is that you are running mvn install:install-file on your project. Run mvn install instead.

Maven-Wagon - How to rename resources with special characters?

I try to use the Mave-Wagon plugin to download a file via HTTP-GET:
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<id>download-zip</id>
<phase>generate-sources</phase>
<goals>
<goal>download-single</goal>
</goals>
<configuration>
<url>http://server.com/Download/</url>
<fromFile>FileDownload.aspx?param=asdf&param2=1234</fromFile>
<toDir>${project.build.directory}</toDir>
<toFile>targetfilename.zip</toFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem is the ? in the target filename as the toFile is applied only after the download happened.
When I download the URL via a normal browser, the browser gives me also a "clean" and nice file name. Is this HTTP-Header ignored by Wagon-HTTP?
Is there any way to pass the parameters to the URL or make Maven to use another/cleaned file name?
For completeness, the whole exception is
Caused by: java.io.FileNotFoundException: Illegal Syntax in filename (sorry this is an translation)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:145)
at org.apache.maven.wagon.LazyFileOutputStream.initialize(LazyFileOutputStream.java:154)
at org.apache.maven.wagon.LazyFileOutputStream.write(LazyFileOutputStream.java:126)
at org.apache.maven.wagon.AbstractWagon.transfer(AbstractWagon.java:492)
at org.apache.maven.wagon.AbstractWagon.getTransfer(AbstractWagon.java:328)
... 25 more
The Wagon plugin exposes the Wagon API, and the Wagon API is not a general purpose remote file system access API. It's intended only to push content in and out of Maven repositories, not arbitrary files to arbitrary places. I'd recommend using the maven-antrun-plugin and ssh as in this example.

Resources