This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Maven: plugin vs dependency

 
Greenhorn
Posts: 18
Python Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, the book I am reading is telling me to install the maven surefire plugin. It shows it installed (in the pom file) as:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<testErrorIgnore>false</testErrorIgnore>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>

However, when I search for it myself in mvnrepository, it shows like this:

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <version>2.19.1</version>
</dependency>

1. Why can't I find the text for installing this as a plugin?
2. Am I totally missing the point? to be honest, I don't quite understand the difference between plugin and dependency. As far as I understand, you can use either as a way to get what you want into the project
3. I can see that the plugin text also has a <configuration> tag, does the <dependency> text also support this?

Any general advice about this would be accepted right now, as the book doesn't seem to elaborate but future projects depend on this.
PS: Sorry but please let's keep Gradle>Maven discussion out
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Todor, welcome to the Ranch!

Does the book say where you should install this plugin? For example, Eclipse works with plugins so it might be referring to Eclipse. Or since "plugin" is a generic term in programming it might be referring to something else which uses plugins. It's impossible for somebody to explain how to install a plugin without knowing where it's going to be installed.
 
Todor Kolev
Greenhorn
Posts: 18
Python Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice to be here, thank you!

"It shows it installed (in the pom file)"
Also, the question is about Maven, not eclipse or an unknown plugin host
 
Paul Clapham
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Todor Kolev wrote:Also, the question is about Maven, not eclipse or an unknown plugin host



So I've moved your post to the Maven forum.
 
Saloon Keeper
Posts: 21127
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maven is a self-sufficient build system, so both plugins and dependencies are handled in much the same way. That is, when running Maven, Maven will look for the indicated items and automatically download them if they're not already downloaded (in the user's local repository).

Plugins contain the code to accomplish one or more Maven goals. Dependencies are jars that are required to build and/or become part of the target product.

Surefire is a plugin that runs unit tests and generates reports. I think it's actually pre-installed standard with Maven, in which case, the primary use of a plugin definition for it in a POM would be to ensure the total reproducibility of the build by ensuring that not only were the right dependency versions being used but that a known good version of Surefire was being used.

You should not use <dependency> to install Surefire. It should properly be defined for what it is: a plugin. For example:
 
Todor Kolev
Greenhorn
Posts: 18
Python Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a very thoughtful answer - thank you!
I agree that it's more of plugin because you can call to it from the command line ('mvn test'), before any project has been built or any dependency resolved.

That's why I am still confused: why does the mvnrepository only give me the xml text for adding surefire as a dependency? Shouldn't they have provided the plugin syntax?
 
Tim Holloway
Saloon Keeper
Posts: 21127
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite a number of applications can operate in multiple modes. For example, the jalopy code beautifier. Or, for that matter, the Tomcat web application server, which not only has a long history of being run embedded (in fact it was the servlet/JSP engine for JBoss for a long time), but is very commonly run that way via Spring Boot.

Java-based applications of this type are frequently centered around a top-level JavaBean that acts as the interface when another Java application wants to invoke it. Much more civilized than simply doing a brute-force Runtime.exec().

So the fact that you can run Surefire both as a stand-alone command-line app and as a Maven plugin is simply because it was designed to operate in both modes. Likely, you can also invoke it as an Ant task as well, since Ant, like Maven handles plugins as JavaBeans.

When you invoke an app such as Surefire using its JavaBean interface, there is no command line and thus no command-line syntax for Maven. Instead you set plugin properties in the POM and the  Maven POM digester collects those properties and injects them into the JavaBean.
 
Tim Holloway
Saloon Keeper
Posts: 21127
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is - I hope! - more formal documentation for Surefire options, but the source code has annotations that should make them clear:

https://github.com/apache/maven-surefire/blob/master/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java

Also, note that Surefire itself has plugins of its own. They handle different Surefire report formats, for example.
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!