Skip to content
TheChatArchiveThe Chat Archive
Googlegemma-3-27b-it· GoogleHugging Face LMArena Human Preference 140K

me mostre o uso do JGitVer em um projeto java 8 e spring boot 2.1.6.RELEASE. maven e git.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Kimikimi-k2-0711-preview’s answer.
  1. User

    me mostre o uso do JGitVer em um projeto java 8 e spring boot 2.1.6.RELEASE. maven e git.

  2. Google Assistant

    Ok, vamos configurar o JGitVer em um projeto Java 8, Spring Boot 2.1.6.RELEASE, usando Maven e Git. Este guia detalhado te mostrará como fazer isso passo a passo.


    📦 Passo 1: Configuração do Projeto Maven

    1. Crie um projeto Spring Boot: Use o Spring Initializr (https://start.spring.io/) para criar um projeto com as dependências básicas (Web, Maven).

    2. pom.xml: Adicione o plugin JGitVer ao seu pom.xml:

    <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.6.RELEASE</version>
            <relativePath/>
        </parent>
        <groupId>com.example</groupId>
        <artifactId>jgitver-spring-boot</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>jgitver-spring-boot</name>
        <description>Demo project for Spring Boot with JGitVer</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
    
                <!-- JGitVer Maven Plugin -->
                <plugin>
                    <groupId>fr.brouillard.oss</groupId>
                    <artifactId>jgitver-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <extensions>true</extensions>
                    <configuration>
                        <strategy>MAVEN</strategy>
                        <tagVersionPattern>^v(.*)$</tagVersionPattern>
                        <nonQualifierBranches>master,main</nonQualifierBranches>
                        <useDistance>true</useDistance>
                        <useGitCommitId>true</useGitCommitId>
                        <useDirty>true</useDirty>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    📦 Passo 2: Inicialização do Repositório Git

    1. Inicialize o Git:

      git init
      git add .
      git commit -m "Initial commit"
      
    2. Crie uma tag inicial:

      git tag -a v1.0.0 -m "Initial release"
      

    📦 Passo 3: Controller para Exibir a Versão

    Crie um controller simples para exibir a versão do projeto:

    package com.example.jgitverspringboot;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class VersionController {
    
        @Value("${project.version:unknown}")
        private String projectVersion;
    
        @GetMapping("/version")
        public String getVersion() {
            return "Versão do projeto: " + projectVersion;
        }
    }
    

    📦 Passo 4: Configuração do application.properties

    Adicione a seguinte linha ao seu src/main/resources/application.properties:

    project.version=@project.version@
    

    📦 Passo 5: Executando e Verificando

    1. Compile o projeto:

      mvn clean compile
      
    2. Execute o projeto:

      mvn spring-boot:run
      
    3. Acesse a URL: Abra seu navegador e acesse http://localhost:8080/version. Você deverá ver a versão do projeto (ex: Versão do projeto: 1.0.0).

    📦 Passo 6: Testando o Versionamento

    1. Faça algumas alterações no código: Adicione uma nova linha de código em um dos seus arquivos Java.

    2. Commit as alterações:

      git add .
      git commit -m "feat: Adicionada nova funcionalidade"
      
    3. Verifique a versão novamente: Compile e execute o projeto novamente. Acesse http://localhost:8080/version. A versão deverá ser atualizada (ex: Versão do projeto: 1.0.1-1).

    4. Crie uma nova tag:

      git tag -a v1.1.0 -m "Nova release"
      
    5. Verifique a versão novamente: Compile e execute o projeto novamente. Acesse http://localhost:8080/version. A versão deverá ser atualizada para 1.1.0.


    Observações:

    • @project.version@: Esta propriedade é substituída pelo JGitVer durante o processo de build.
    • strategy: A estratégia MAVEN é a mais comum para projetos Maven.
    • tagVersionPattern: Define o padrão para extrair a versão das tags Git.
    • nonQualifierBranches: Define as branches que não devem ter um qualificador (ex: -SNAPSHOT).
    • useDistance: Inclui a distância do commit na versão.
    • useGitCommitId: Inclui o hash do commit na versão.
    • useDirty: Marca a versão como "dirty" se houver mudanças não commitadas.

    Este guia deve te dar um bom ponto de partida para usar o JGitVer em seu projeto Spring Boot. Se tiver alguma dúvida, pode perguntar!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.