0

I'm new to Maven and I've just made some simple app. Now I'm trying to commit my code to GitLab repo and I ran into some problems. I'm using maven-scm-plugin and I just can't push my code to GitLab repo.

part of pom.xml file:

<scm>
    <url>http://path.to.my.repo</url>
    <connection>scm:git:http://path.to.my.repo.git</connection>
    <developerConnection>scm:git:http://path.to.my.repo.git</developerConnection>
</scm>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.9.5</version>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-plugin</artifactId>
            <configuration>
                <username>user</username>
                <password>pass</password>
                <goals>install</goals>
            </configuration>
        </plugin>
    </plugins>
</build>

I already managed to commit code on a remote repo with the following sequence of git commands:

// initialization
git init

// adding files to staging area
git add .

// commit to local repo
git commit -m "Initial commit"

// set remote url
git remote add origin http://path.to.my.repo

// push
git push origin master

Based on maven-scm-plugin docs I just can't figure it out what is the correct order of commands to achieve the same as using git commands listed above. Any help?

peterremec
  • 488
  • 1
  • 15
  • 46
  • What is the purpose to commit code via Maven instead of command line? (or IDE? ) ? – khmarbaise May 18 '18 at 10:01
  • It's not that I need to do it with Maven. Since Maven obviously makes it possible, I'm just trying that option, too. Or is there any reason for not doing it that way? – peterremec May 18 '18 at 10:13
  • Theoretically, you can perform releases with maven, but I wouldn't rely on maven with this task unless you're willing to report bugs and contribute fixes – basin May 18 '18 at 10:30
  • @basin What kind of problems do you have? – khmarbaise May 18 '18 at 11:04
  • @peterremec Can you show the maven command(s) you used and the outputs? – Marina Liu May 21 '18 at 03:35
  • @MarinaLiu-MSFT I'm having problem right at git repo initialization. I couldn't find any maven-scm-plugin command to init repo. Then I checked plugin docs again and I noticed the following sentence: ***"The files should be added beforehand by an external scm client."*** Does that mean that you have to use `git init` and `git add .` first and then you can commit code using `mvn scm:checkin`? – peterremec May 21 '18 at 06:15
  • @peterremec Yes, you need to create a git repo by git command firstly since maven commands of the maven-scm-plugin (mvn scm:xxx) can not create a git repo. – Marina Liu May 21 '18 at 06:19
  • @MarinaLiu-MSFT that explains a lot. Tried with `git init` to create repo and `git add .` to add all files to staging area, and now `mvn -Dmessage="msg" scm:checkin` command commits the code on remote GitLab repo. Thank you very much for your explanation! – peterremec May 21 '18 at 06:29

1 Answers1

0

maven-scm-plugin can be used to commit change to git repo by the command mvn scm:checkin.

But for creating a git repo, there is no such maven commands to equal with the command git init.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74