Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ This is the [exec-maven-plugin](http://www.mojohaus.org/exec-maven-plugin/).

## Running integration tests

Execute `mvn -P run-its clean verify`
Execute

```sh
mvn -P run-its clean verify
```

Running a single test:

```sh
mvn -P run-its clean verify "-Dinvoker.test=setup-parent,<TEST-PROJECT-NAME>"
```

## Releasing

Expand Down
39 changes: 39 additions & 0 deletions src/it/projects/custom-plugin-repository/build-dependency/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
<relativePath/>
</parent>

<artifactId>custom-plugin-repository-build</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>
Builds a JAR and installs it into a custom local Maven repository
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
<localRepositoryPath>${project.basedir}/../custom-repo</localRepositoryPath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package example;

public class Main
{
public static void main( String[] args ) throws Exception {
System.out.println( "Can you hear me, Major Tom?" );
}
}
6 changes: 6 additions & 0 deletions src/it/projects/custom-plugin-repository/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# First build and install dependency in custom repo
invoker.project.1 = build-dependency
invoker.goals.1 = clean package

# Then try to use dependency from custom repo
invoker.goals.2 = clean process-resources
66 changes: 66 additions & 0 deletions src/it/projects/custom-plugin-repository/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>

<artifactId>custom-plugin-repository-use</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>
Tests executing a JAR which only exists in a custom Maven repository but not in Central
</description>

<pluginRepositories>
<pluginRepository>
<id>custom-repo</id>
<!-- Note: On Windows using `project.basedir` includes backslashes in this URI, which is not ideal
but seems to work -->
<url>file:///${project.basedir}/custom-repo</url>
Comment on lines +20 to +23
Copy link
Author

@Marcono1234 Marcono1234 Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, this leads to something like (note the \ in the path):

[INFO] Downloading from custom-repo: file:///C:\Users\...

I think technically this is not a valid file: URI, but it seems Maven / Java seems to accept it nonetheless.
Not sure how this can be easily solved. Using file:///./custom-repo did not seem to work, maybe because the working directory is actually in one of its parent dirs (or something was wrong with my test setup)?

<snapshots>
<enabled>true</enabled>
<!-- Test setup does not generate checksum files for artifact -->
<checksumPolicy>ignore</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<addOutputToClasspath>false</addOutputToClasspath>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>custom-plugin-repository-build</artifactId>
</executableDependency>
<mainClass>example.Main</mainClass>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>custom-plugin-repository-build</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
24 changes: 24 additions & 0 deletions src/it/projects/custom-plugin-repository/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

File buildLog = new File(basedir, 'build.log')
assert buildLog.exists()
def buildLogText = buildLog.getText()
// Should contain program output
assert buildLogText.contains('Can you hear me, Major Tom?')
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ private Set<Artifact> resolveExecutablePluginDependencies(Artifact executableArt
try {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(RepositoryUtils.toArtifact(executableArtifact), classpathScope));
// as this method is called only determineRelevantPluginDependencies, se we need a plugin repository here
// this method is called only by determineRelevantPluginDependencies, so we need a plugin repository here
collectRequest.setRepositories(project.getRemotePluginRepositories());

DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(classpathScope);
Expand Down