<profile> <id>deploy-deps</id> <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <useSubDirectoryPerScope>true</useSubDirectoryPerScope> <excludeGroupIds> , war-</excludeGroupIds> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <id>05-stop-tomcat</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>${tomcat.dir.root}/bin/shutdown.sh</argument> </arguments> <executable>plink</executable> </configuration> </execution> <execution> <id>10-clean-shared-jars</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>rm</argument> <argument>-Rf</argument> <argument>${tomcat.dir.shared}/*.jar</argument> </arguments> <executable>plink</executable> </configuration> </execution> <execution> <id>15-upload-shared-jars</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-scp</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${project.build.directory}/dependency/compile/*.jar</argument> <argument>${ssh.user}@${ssh.host}:${tomcat.lib.shared}/</argument> </arguments> <executable>pscp</executable> </configuration> </execution> <execution> <id>20-start-tomcat</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>"${putty.key}"</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>bin/startup.sh</argument> </arguments> <executable>plink</executable> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
org.apache.maven.plugin-tools:maven-plugin-annotations
for the possibility of specifying Mojo classes not through JavaDoc, but using annotationsorg.twdata.maven:mojo-executor
to be able to run other plugins from ours. @Mojo(name = "deploy-deps", defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true) public class DeployDepsMojo extends AbstractMojo { @Component protected MavenProject mavenProject; @Component protected MavenSession mavenSession; @Component protected BuildPluginManager pluginManager; protected MojoExecutor.ExecutionEnvironment _pluginEnv; @Override public void execute() throws MojoExecutionException, MojoFailureException { _pluginEnv = executionEnvironment(mavenProject, mavenSession, pluginManager); } }
<build> <!-- ... --> <plugins> <plugin> <artifactId>maven-plugin-plugin</artifactId> <executions> <execution> <id>help-goal</id> <goals> <goal>helpmojo</goal> </goals> </execution> <execution> <id>mojo-descriptor</id> <goals> <goal>descriptor</goal> </goals> </execution> </executions> <configuration> <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> </configuration> </plugin> </plugins> </build>
<plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <useSubDirectoryPerScope>true</useSubDirectoryPerScope> <excludeGroupIds> , war-</excludeGroupIds> </configuration> </execution> </executions> </plugin>
@Mojo(name = "deploy-deps", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true) public class DeployDepsMojo extends AbstractMojo { // ... @Override public void execute() throws MojoExecutionException, MojoFailureException { _pluginEnv = executionEnvironment(mavenProject, mavenSession, pluginManager); copyDependencies(); } private void copyDependencies() throws MojoExecutionException { // TODO expects corrections https://github.com/TimMoore/mojo-executor/issues/18 Plugin pluginDependency = plugin("org.apache.maven.plugins", "maven-dependency-plugin", "2.8"); final Xpp3Dom cfg = configuration(element(name("useSubDirectoryPerScope"), "true")); executeMojo(pluginDependency, goal("copy-dependencies"), cfg, _pluginEnv); } }
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <id>05-stop-tomcat</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>${tomcat.dir.root}/bin/shutdown.sh</argument> </arguments> <executable>plink</executable> </configuration> </execution> <!-- ... --> </executions> </plugin>
public class DeployDepsMojo extends AbstractMojo { public static final String PLG_EXEC_CFG_ARGUMENTS = "arguments"; public static final Xpp3Dom PLG_EXEC_CFG_EXEC_PLINK = element(name("executable"), "plink").toDom(); public static final String PLG_EXEC_GOAL_EXEC = goal("exec"); public static final String PLG_EXEC_PROTOCOL_SSH = "-ssh"; // ... @Override public void execute() throws MojoExecutionException, MojoFailureException { _pluginEnv = executionEnvironment(mavenProject, mavenSession, pluginManager); _pluginExec = plugin("org.codehaus.mojo", "exec-maven-plugin", "1.2.1"); copyDependencies(); tomcatShutdown(); } private void tomcatShutdown() throws MojoExecutionException { Xpp3Dom cfg = getBaseConfigExec(PLG_EXEC_PROTOCOL_SSH); final Xpp3Dom arguments = cfg.getChild(PLG_EXEC_CFG_ARGUMENTS); arguments.addChild(element(name("argument"), "${ssh.user}@${ssh.host}").toDom()); arguments.addChild(element(name("argument"), "bin/shutdown.sh").toDom()); cfg.addChild(PLG_EXEC_CFG_EXEC_PLINK); executeMojo(_pluginExec, PLG_EXEC_GOAL_EXEC, cfg, _pluginEnv); } private Xpp3Dom getBaseConfigExec(String protocol) { final Element el0 = element(name("argument"), protocol); final Element el1 = element(name("argument"), "-4"); final Element el2 = element(name("argument"), "-agent"); final Element el3 = element(name("argument"), "-i"); final Element el4 = element(name("argument"), "${putty.key}"); return configuration(element(name(PLG_EXEC_CFG_ARGUMENTS), el0, el1, el2, el3, el4)); } }
<profile> <id>deploy-deps</id> <build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <useSubDirectoryPerScope>true</useSubDirectoryPerScope> <excludeGroupIds> , war-</excludeGroupIds> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <id>05-stop-tomcat</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>${tomcat.dir.root}/bin/shutdown.sh</argument> </arguments> <executable>plink</executable> </configuration> </execution> <execution> <id>10-clean-shared-jars</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>rm</argument> <argument>-Rf</argument> <argument>${tomcat.dir.shared}/*.jar</argument> </arguments> <executable>plink</executable> </configuration> </execution> <execution> <id>15-upload-shared-jars</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-scp</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>${putty.key}</argument> <argument>${project.build.directory}/dependency/compile/*.jar</argument> <argument>${ssh.user}@${ssh.host}:${tomcat.lib.shared}/</argument> </arguments> <executable>pscp</executable> </configuration> </execution> <execution> <id>20-start-tomcat</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <arguments> <argument>-ssh</argument> <argument>-4</argument> <argument>-agent</argument> <argument>-i</argument> <argument>"${putty.key}"</argument> <argument>${ssh.user}@${ssh.host}</argument> <argument>bin/startup.sh</argument> </arguments> <executable>plink</executable> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>
<profile> <id>deploy-deps</id> <build> <plugins> <plugin> <groupId>info.alenkov.tools.maven</groupId> <artifactId>tomcat7-ewar-plugin</artifactId> <executions> <execution> <phase>process-sources</phase> <goals> <goal>deploy-deps</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile>
mvn clean process-sources tomcat7-ewar:deploy-deps
Source: https://habr.com/ru/post/205118/
All Articles