Search code examples
mavengitlab-api

problem deploying maven dependency to GitLab


I have a POM file that I use to deploy a library to a local maven repository. I want to deploy it to GitLab now, as per here, but while I get BUILD SUCCESS, I never get Uploading to gitlab-maven. I am not even sure it tries.

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mobiwms</groupId>
    <artifactId>jaxb</artifactId>
    <packaging>jar</packaging>
    <name>wmsvisionjaxb</name>
    <version>0.5.11.47</version>

    <properties>
        <gitlab.jaxb.projectid>PROJECT_ID</gitlab.jaxb.projectid>
    </properties>

    <repositories>
        <repository>
            <id>gitlab-maven</id>
            <!-- Instance level endpoint
            <url>https://gitlab.com/api/v4/packages/maven</url>
            -->
            <url>https://gitlab.com/api/v4/projects/${gitlab.jaxb.projectid}/packages/maven</url>
        </repository>
    </repositories>
    <distributionManagement>
        <repository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/projects/${gitlab.jaxb.projectid}/packages/maven</url>
        </repository>
        <snapshotRepository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/projects/${gitlab.jaxb.projectid}/packages/maven</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.3</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
        </plugins>
    </build>

</project>

setting.xml:

<settings>
  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Private-Token</name>
            <value><Personal Access Tokenm api scope></value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>

Command with results:

+ mvn deploy:deploy-file -Durl=file:///home/<user id>/.m2/repository -Dfile=dist/wmsvisionjaxb-0.5.11.47.jar -Dsources=dist/wmsvisionjaxb-0.5.11.47-sources.jar -DpomFile=pom.xml -DperformRelease=true -DcreateChecksum=true -Dversion=0.5.11.47 -s settings.xml
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building wmsvisionjaxb 0.5.11.47
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (default-cli) @ jaxb ---
Uploading: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.jar
Uploaded: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.jar (5063 KB at 20011.2 KB/sec)
Uploading: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.pom
Uploaded: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.pom (2 KB at 1761.7 KB/sec)
Downloading: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/maven-metadata.xml
Downloaded: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/maven-metadata.xml (20 KB at 6360.0 KB/sec)
Uploading: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/maven-metadata.xml
Uploaded: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/maven-metadata.xml (20 KB at 681.4 KB/sec)
Uploading: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47-sources.jar
Uploaded: file:///home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47-sources.jar (3011 KB at 48556.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.374s
[INFO] Finished at: Mon Nov 20 17:04:27 EST 2023
[INFO] Final Memory: 7M/24M
[INFO] ------------------------------------------------------------------------
+ set +x
Buildfile: /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/build.xml

print-version:
     [echo] Java/JVM version: 1.8
     [echo] Java/JVM detail version: 1.8.0_212
     [echo] Java Home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre

BUILD SUCCESSFUL
Total time: 0 seconds

Yes, I did try just mvn deploy, but I get unauthorized in that case, and it does not use the correct version, which is why I use the convoluted command above. I would prefer to keep using something like the above command as it is more flexible in my use case, so if someone could tell me why I don't even talk to gitlab, that would be great.

I am currently researching the 401 error - I saw lots of examples of that error, with solutions, on the boards. So no need to address that issue just yet. Just need to know why my POM and maven command combination above is not even talking to GitLab.

Update: As expected, found 401 error and fixed it. But I definitely need to figure out why mvn deploy uploads to gitlab but deploy:deploy-file does not, does not even seem to talk to gitlab. I sort of have to use deploy-file because I am not actually building anything, just uploading it to a repository. Maybe deploy-file does something weird that preempts upload to gitlab?

Incidentally, this is what I get if I don't use deploy-file:

+ mvn deploy -Durl=file:///home/<user id>/.m2/repository -Dfile=dist/wmsvisionjaxb-0.5.11.47.jar -Dsources=dist/wmsvisionjaxb-0.5.11.47-sources.jar -DpomFile=pom.xml -DperformRelease=true -DcreateChecksum=true -Dversion=0.5.11.47 -s settings.xml
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building wmsvisionjaxb 0.5.11.47
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ jaxb ---
[debug] execute contextualize
[WARNING] Using platform encoding (ISO-8859-1 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ jaxb ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ jaxb ---
[debug] execute contextualize
[WARNING] Using platform encoding (ISO-8859-1 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ jaxb ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ jaxb ---
[INFO] No tests to run.
[INFO] Surefire report directory: /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ jaxb ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/target/jaxb-0.5.11.47.jar
[INFO] 
[INFO] >>> maven-source-plugin:2.4:jar (attach-sources) @ jaxb >>>
[INFO] 
[INFO] <<< maven-source-plugin:2.4:jar (attach-sources) @ jaxb <<<
[INFO] 
[INFO] --- maven-source-plugin:2.4:jar (attach-sources) @ jaxb ---
[INFO] No sources in project. Archive not created.
[INFO] 
[INFO] --- maven-javadoc-plugin:2.10.3:jar (attach-javadocs) @ jaxb ---
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ jaxb ---
[INFO] Installing /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/target/jaxb-0.5.11.47.jar to /home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.jar
[INFO] Installing /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/pom.xml to /home/<user id>/.m2/repository/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ jaxb ---
Uploading: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.jar
Uploaded: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.jar (2 KB at 0.7 KB/sec)
Uploading: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.pom
Uploaded: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/0.5.11.47/jaxb-0.5.11.47.pom (2 KB at 0.9 KB/sec)
Downloading: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/maven-metadata.xml
Downloaded: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/maven-metadata.xml (334 B at 0.6 KB/sec)
Uploading: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/maven-metadata.xml
Uploaded: https://gitlab.com/api/v4/projects/52325873/packages/maven/com/mobiwms/jaxb/maven-metadata.xml (334 B at 0.2 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.572s
[INFO] Finished at: Mon Nov 20 17:08:58 EST 2023
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------
+ set +x
Buildfile: /home/wms/v10_odbc/std/lcn/src/issi/web/website/wmsvision_jaxb/build.xml

print-version:
     [echo] Java/JVM version: 1.8
     [echo] Java/JVM detail version: 1.8.0_212
     [echo] Java Home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre

BUILD SUCCESSFUL
Total time: 0 seconds

Note how much more it does when I remove deploy-file. Granted, it also tries to rebuild things, which is why the jar file is virtually empty.


Solution

  • Solution in maven command line: changed -Durl=file:///home/<user id>/.m2/repository to -Durl=https://gitlab.com/api/v4/projects/$GitLabProjectId/packages/maven, and added -DrepositoryId=gitlab-maven.

    I guess my assumption that deploy-file would fall back to pom.xml values was wrong, because I had to include -Durl option.

    If anyone has a better solution, tell me.