();
+ Class> superClass = GreetingRequest.class;
+
+ do {
+ superClasses.add(superClass.getName());
+ superClass = superClass.getSuperclass();
+ } while (superClass != null);
+
+ // Then
+ // GeneratedMessageV3 for protobuf-java 3.25.3 and older.
+ // GeneratedMessage for protobuf-java 4.26.0 and newer.
+ assertTrue(superClasses.contains("com.google.protobuf.GeneratedMessage"));
+ }
+
+ @Test
+ void generatedProtobufSourcesAreValid() throws Throwable {
+ // Given
+ var expectedGreetingRequest = GreetingRequest
+ .newBuilder()
+ .setName("Ashley")
+ .build();
+
+ // When
+ var baos = new ByteArrayOutputStream();
+ expectedGreetingRequest.writeTo(baos);
+ var actualGreetingRequest = GreetingRequest.parseFrom(baos.toByteArray());
+
+ assertNotEquals(0, baos.toByteArray().length);
+
+ // Then
+ assertEquals(expectedGreetingRequest.getName(), actualGreetingRequest.getName());
+ }
+}
diff --git a/protobuf-maven-plugin/src/it/java-test-legacy-source-directory/src/test/proto/helloworld.proto b/protobuf-maven-plugin/src/it/java-test-legacy-source-directory/src/test/proto/helloworld.proto
new file mode 100644
index 00000000..549aa0cf
--- /dev/null
+++ b/protobuf-maven-plugin/src/it/java-test-legacy-source-directory/src/test/proto/helloworld.proto
@@ -0,0 +1,27 @@
+//
+// Copyright (C) 2023 - 2025, Ashley Scopes.
+//
+// Licensed 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.
+//
+
+syntax = "proto3";
+
+option java_multiple_files = true;
+option java_package = "org.example.helloworld";
+
+package org.example.helloworld;
+
+message GreetingRequest {
+ string name = 1;
+}
+
diff --git a/protobuf-maven-plugin/src/it/java-test-legacy-source-directory/test.groovy b/protobuf-maven-plugin/src/it/java-test-legacy-source-directory/test.groovy
new file mode 100644
index 00000000..bfba6074
--- /dev/null
+++ b/protobuf-maven-plugin/src/it/java-test-legacy-source-directory/test.groovy
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2023 - 2025, Ashley Scopes.
+ *
+ * Licensed 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.
+ */
+import java.nio.file.Path
+
+import static org.assertj.core.api.Assertions.assertThat
+
+Path baseDirectory = basedir.toPath().toAbsolutePath()
+Path generatedSourcesDir = baseDirectory.resolve("target/generated-test-sources/protobuf")
+def classesDir = baseDirectory.resolve("target/test-classes")
+def expectedGeneratedFiles = [
+ "org/example/helloworld/Helloworld",
+ "org/example/helloworld/GreetingRequest",
+ "org/example/helloworld/GreetingRequestOrBuilder",
+]
+
+assertThat(generatedSourcesDir).isDirectory()
+
+assertThat(classesDir).isDirectory()
+
+expectedGeneratedFiles.forEach {
+ assertThat(generatedSourcesDir.resolve("${it}.java"))
+ .exists()
+ .isNotEmptyFile()
+ assertThat(classesDir.resolve("${it}.class"))
+ .exists()
+ .isNotEmptyFile()
+}
+
+return true
diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java
index 98b3a4c0..35e8722e 100644
--- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java
+++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java
@@ -912,6 +912,9 @@ public AbstractGenerateMojo() {
* Override the source directories to compile from.
*
* Leave unspecified or explicitly null/empty to use the defaults.
+ *
+ *
Note that specifying custom directories will override the default
+ * directories rather than adding to them.
*
* @since 0.0.1
*/
diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojo.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojo.java
index 7e13f6c3..aba882cf 100644
--- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojo.java
+++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojo.java
@@ -35,7 +35,8 @@
*
Any project dependencies using the {@code compile}, {@code provided},
* or {@code system} scopes will be made available to import from protobuf sources.
*
- *
By default, sources will be read from {@code src/main/protobuf},
+ *
By default, sources will be read from {@code src/main/protobuf} ({@code src/main/proto},
+ * is also supported to assist in migration off of other unmaintained Maven plugins),
* and generated sources will be written to {@code target/generated-sources/protobuf}.
*
* @author Ashley Scopes
@@ -74,9 +75,14 @@ Set defaultDependencyScopes() {
Collection defaultSourceDirectories() {
var basePath = mavenProject.getBasedir().toPath()
.resolve("src")
- .resolve("main")
- .resolve("protobuf");
- return List.of(basePath);
+ .resolve("main");
+
+ return List.of(
+ basePath.resolve("protobuf"),
+ // Provided in GH-687 as a transition layer for other plugin users
+ // migrating onto this Maven plugin.
+ basePath.resolve("proto")
+ );
}
@Override
diff --git a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojo.java b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojo.java
index 5a1eb0ff..f8370fa9 100644
--- a/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojo.java
+++ b/protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojo.java
@@ -35,7 +35,8 @@
* Any project dependencies using the {@code compile}, {@code provided},
* {@code system}, or {@code test} scopes will be made available to import from protobuf sources.
*
- *
By default, sources will be read from {@code src/test/protobuf},
+ *
By default, sources will be read from {@code src/test/protobuf} ({@code src/test/proto},
+ * is also supported to assist in migration off of other unmaintained Maven plugins),
* and generated sources will be written to {@code target/generated-test-sources/protobuf}.
*
*
Generally, you won't need to use this. It can be useful in some more
@@ -76,9 +77,14 @@ Set defaultDependencyScopes() {
Collection defaultSourceDirectories() {
var basePath = mavenProject.getBasedir().toPath()
.resolve("src")
- .resolve("test")
- .resolve("protobuf");
- return List.of(basePath);
+ .resolve("test");
+
+ return List.of(
+ basePath.resolve("protobuf"),
+ // Provided in GH-687 as a transition layer for other plugin users
+ // migrating onto this Maven plugin.
+ basePath.resolve("proto")
+ );
}
@Override
diff --git a/protobuf-maven-plugin/src/site/markdown/basic-usage.md b/protobuf-maven-plugin/src/site/markdown/basic-usage.md
index f6cd1ce1..10859a47 100644
--- a/protobuf-maven-plugin/src/site/markdown/basic-usage.md
+++ b/protobuf-maven-plugin/src/site/markdown/basic-usage.md
@@ -91,6 +91,18 @@ generated protobuf classes.
---
+## Migration
+
+[GH-692](https://github.com/ascopes/protobuf-maven-plugin/issues/692) introduced the
+fallback source directory of `src/main/proto` and `src/test/proto` to be used to
+assist users who are migrating their codebases off of other unmaintained Maven plugins.
+
+It is recommended that users default to making use of `src/main/protobuf` and
+`src/test/protobuf` instead, as this follows the standard naming convention of other
+Maven-managed projects which is to use the language name rather than the file extension.
+
+---
+
## Goals
By default, this plugin runs the `generate` goal to generate source code designed
diff --git a/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojoTest.java b/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojoTest.java
index 41646bc8..5ad126d5 100644
--- a/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojoTest.java
+++ b/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/MainGenerateMojoTest.java
@@ -39,9 +39,8 @@ SourceRootRegistrar expectedSourceRootRegistrar() {
Collection expectedDefaultSourceDirectories() {
var basePath = mojo.mavenProject.getBasedir().toPath()
.resolve("src")
- .resolve("main")
- .resolve("protobuf");
- return List.of(basePath);
+ .resolve("main");
+ return List.of(basePath.resolve("protobuf"), basePath.resolve("proto"));
}
@Override
diff --git a/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojoTest.java b/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojoTest.java
index aec40469..b676763c 100644
--- a/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojoTest.java
+++ b/protobuf-maven-plugin/src/test/java/io/github/ascopes/protobufmavenplugin/mojo/TestGenerateMojoTest.java
@@ -39,9 +39,8 @@ SourceRootRegistrar expectedSourceRootRegistrar() {
Collection expectedDefaultSourceDirectories() {
var basePath = mojo.mavenProject.getBasedir().toPath()
.resolve("src")
- .resolve("test")
- .resolve("protobuf");
- return List.of(basePath);
+ .resolve("test");
+ return List.of(basePath.resolve("protobuf"), basePath.resolve("proto"));
}
@Override