Skip to content

Instantly share code, notes, and snippets.

@renatoapcosta
Created June 23, 2018 01:35
Show Gist options
  • Save renatoapcosta/9ef408920da159d1ce68ddeced1e5492 to your computer and use it in GitHub Desktop.
Save renatoapcosta/9ef408920da159d1ce68ddeced1e5492 to your computer and use it in GitHub Desktop.
Profiles com Maven

Profiles com Maven

Criando Profiles para a aplicação

No pom.xml adicionamos

<profiles>
    <profile>
	<id>dev</id>
	<properties>
	    <db.senha>root</db.senha>
	    <db.url>localhost</db.url>
	</properties>
    </profile>
</profiles>

Criando um perfil padrão

<profiles>
    <profile>
	<id>dev</id>
	<activation>
	    <activeByDefault>true</activeByDefault>
	</activation>
	<properties>
	    <db.senha>root</db.senha>
	    <db.url>localhost</db.url>
	</properties>
    </profile>
</profiles>

Perfil de produção

<profiles>
    <profile>
	<id>dev</id>
	<activation>
	    <activeByDefault>true</activeByDefault>
	</activation>
	<properties>
	    <db.senha>root</db.senha>
	    <db.url>localhost</db.url>
	</properties>
    </profile>
    <profile>
	<id>prod</id>
	<properties>
	    <db.senha>uma_senha_dificil</db.senha>
	    <db.url>uma_url_diferente</db.url>
	</properties>
    </profile>
</profiles>

Usando nossos profiles

Para o maven procurar nossas variaveis e troca-las por valores devemos utilizar a tag resources.

<build>

	<resources>
	    <resource>
		<directory>${basedir}/src/main/resources</directory>
		<filtering>true</filtering>
	    </resource>
	</resources>

</build>

O Maven olha todos os arquivos dentro desse diretório e se tiver alguma variável, troque por valores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment