Git Product home page Git Product logo

solr-maven-plugin's Introduction

solr-maven-plugin

Build Status Maven Central

A maven plugin to start/stop Apache Solr Cloud.

Install

Releases available on maven Central

<plugin>
    <groupId>io.github.borisnaguet</groupId>
    <artifactId>solr-maven-plugin</artifactId>
    <version>0.5.0</version>
</plugin>

Snapshots (pushed automatically from Travis, on each push) available on Sonatype repository:

<pluginRepositories>
	<pluginRepository>
		<id>ossrh</id>
		<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
		<releases>
			<enabled>false</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</pluginRepository>
</pluginRepositories>
<plugin>
    <groupId>io.github.borisnaguet</groupId>
    <artifactId>solr-maven-plugin</artifactId>
    <version>0.6.0-SNAPSHOT</version>
</plugin>

Use

Please, see solr-maven-plugin-test sub-project for a full example:

  • running Solr cloud with default configuration for before tests
  • stopping after tests
  • starting another configuration (with lots of custom setups) of Solr in pre-integration-test (note that you must enable IT in the example to see that <skipITs>false</skipITs>)
  • stopping it in post-integration-tests

You probably need only one of these (tests or integration-tests), and default configuration is probably enough for most usage.

	<plugin>
		<groupId>io.github.borisnaguet</groupId>
		<artifactId>solr-maven-plugin</artifactId>
		<version>${project.version}</version>
		<executions>
			<!-- Unit tests: tests default configuration parameters -->
			<execution>
				<id>start-tests</id>
				<phase>process-test-resources</phase>
				<goals>
					<goal>start-solrcloud</goal>
				</goals>
				<configuration>
					<skip>${skipTests}</skip>
				</configuration>
			</execution>
			<execution>
				<id>stop-tests</id>
				<phase>prepare-package</phase>
				<goals>
					<goal>stop-solrcloud</goal>
				</goals>
				<configuration>
					<skip>${skipTests}</skip>
					<deleteConf>true</deleteConf>
					<deleteData>true</deleteData>
				</configuration>
			</execution>
			
			<!-- INTEGRATION tests: use of all config -->
			<execution>
				<id>start-IT</id>
				<!-- default phase is pre-integration-test -->
				<goals>
					<goal>start-solrcloud</goal>
				</goals>
				<configuration>
					<skip>${skipITs}</skip>
					<zkPort>9984</zkPort>
					
					<uploadConfig>false</uploadConfig>
					<confToUploadDir>solr-it-conf</confToUploadDir>
					
					<createCols>false</createCols>
					<!-- collections that were previously created in baseDir -->
					<collectionsToCreate>
						<collectionsToCreate>col1</collectionsToCreate>
						<collectionsToCreate>testCol</collectionsToCreate>
					</collectionsToCreate>
					<baseDir>solr-it-data</baseDir>
					<chroot>/solr</chroot>
					<numServers>2</numServers>
				</configuration>
			</execution>
			<execution>
				<id>stop-IT</id>
				<!-- default phase is post-integration-test -->
				<goals>
					<goal>stop-solrcloud</goal>
				</goals>
				<configuration>
					<skip>${skipITs}</skip>
				</configuration>
			</execution>
		</executions>
</plugin> 

All goals and parameters are available on the maven site (with default values and likecycle phases).

Add extra jars

In Solr, you may need to add jars to the classpath of the server, and reference some features in the solrconfig.xml (for example).

To do that, add that to the plugin definition (just after its groupid:artifactid:version):

<dependencies>
	<dependency>
		<groupId>org.apache.solr</groupId>
		<artifactId>solr-analysis-extras</artifactId>
		<version>7.2.1</version>
	</dependency>
	<dependency>
		<groupId>org.apache.solr</groupId>
		<artifactId>solr-dataimporthandler</artifactId>
		<version>7.2.1</version>
	</dependency>
</dependencies>

Now, you can reference it in solrconfig.xml:

<!-- lib import needed for standard deployment (not by plugin) -->
<lib dir="${solr.install.dir:..}/dist/" regex="solr-dataimporthandler-\d.*\.jar" />

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
    </lst>
</requestHandler>

Standalone start

We've seen how to start & stop Solr with your maven build (using default phase or not). But what if you want to start solr using the same version & config and run tests from Eclipse/IntelliJ and/or execute queries manually against it after/before tests. Since version 0.3.0 you can start it with a command line:

mvn io.github.borisnaguet:solr-maven-plugin:run

If you feel it's a bit long, you can use this trick:

mvn solr:run

The previous command will only use the configuration at the plugin level - not inside executions. If you configured the plugin inside an execution, you can specify its id with maven:

mvn solr:run@start-IT

After a while you'll see that:

[INFO] ------------------------------------------------------------------
[INFO] Hit ENTER on the console to stop Solr and continue the build.

So it's better to clean stop with Enter instead of kill.

Solr version

As is, the plugin starts Solr 7.2.1 (will be updated with time of course). If you need another version, you might try to directly change the "classpath" of the plugin:

These are the only dependencies that you need to update:

				<plugin>
					<groupId>io.github.borisnaguet</groupId>
					<artifactId>solr-maven-plugin</artifactId>
					<version>${plugin.version}</version>
					<dependencies>
						<dependency>
							<groupId>org.apache.solr</groupId>
							<artifactId>solr-core</artifactId>
							<version>${solr.version}</version>
						</dependency>
						<dependency>
							<groupId>org.apache.solr</groupId>
							<artifactId>solr-test-framework</artifactId>
							<version>${solr.version}</version>
						</dependency>
					</dependencies>
...

Of course, it can only work until some breaking change is introduced somewhere. Please inform me if this doesn't work on a particular version.

Also please note that Solr 6+ requires Java 8 (Since 0.5.0 this plugin also needs Java 8 - use 0.4.0 if you need to run older release of Solr).

To improve

This plugin is already used in a large professional project, but it could still be improved.

Build (for maven plugin developpers)

If you want to fork this project and make changes to the plugin, you'll only need to use maven install

Contribute

Yes!

Please fill an issue, or a PR. https://github.com/BorisNaguet/solr-maven-plugin/issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.