[Spring Framework] maven pom.xml에서 dependency와 plugin 차이점은?

프로그래밍/서버2020. 12. 5. 21:34

스프링 프레임워크를 공부하다가 maven pom.xml에서 쓰이는 <dependency>와 <plugin>의 차이가 무엇인지 궁금해서 찾아봤습니다.

 

    <dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</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>
		</plugins>
	</build>

 

아래의 링크 답변이 좋은 것 같네요.

stackoverflow.com/questions/26292073/whats-the-difference-between-maven-plugins-and-dependencies

 

Dependencies are artifacts (i.e. a jar) that your project requires to be available in its classpath at some point in time (i.e. at compile time or runtime)

A plugin however is an artifact that you can configure in your project to have it actually do something during the build of your project. (so for example there are plugins to actually compile your java classes, to copy files or to start and stop a database among many others). A plugin is not available on your project's classpath.

Taking Neo4J as an example, you would include it as a dependency if your project requires the neo4j classes to be available on the classpath - maybe because you are compiling against their API. If however you simply need a Neo4J server to be running for your tests, then you would use the Neo4J plugin to have it start a server before Maven runs your tests and then the plugin would stop the server after the tests have completed.

I would recommend taking a read of Sonatype's book Maven: A Complete Reference for more details on Maven in general.

  

<dependency>는 컴파일 혹은 런타임의 특정 상황에 클래스패쓰에서 사용할 수 있도록 프로젝트에서 요구하는 jar파일 이라고 합니다. 그냥 우리가 아는.. 외부 라이브러리를 단순 사용하기 위해서 쓰는, 흔히 말하는 디펜던시인 것 같네요.

<plugin>은 프로젝트 빌드 과정에서 실제로 무언가를 하기 위해 설정하는 jar파일이라고 합니다. 테스트를 위해 Neo4j t서버가 필요한 경우 <plugin>에 Neo4j를 추가하면 Maven이 테스트를 하기 전 Neo4j 서버를 실행하게 됩니다. 테스트가 끝나면 Neo4j 서버는 종료됩니다.

 

 

 

작성자

Posted by 드리머즈

관련 글

댓글 영역