Register java_plugin in PrepareForTestWithJavaBuildComponents

Bug: 182885307
Test: m nothing
Change-Id: I550d39ba46c548b6b099d8dc6a9c458ca931b2fa
diff --git a/java/java_test.go b/java/java_test.go
index d27a73d..19d8006 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -74,8 +74,6 @@
 	PrepareForTestWithOverlayBuildComponents,
 	python.PrepareForTestWithPythonBuildComponents,
 	android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
-		ctx.RegisterModuleType("java_plugin", PluginFactory)
-
 		ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory)
 	}),
 	dexpreopt.PrepareForTestWithDexpreopt,
diff --git a/java/plugin.go b/java/plugin.go
index 947c286..297ac2c 100644
--- a/java/plugin.go
+++ b/java/plugin.go
@@ -17,7 +17,11 @@
 import "android/soong/android"
 
 func init() {
-	android.RegisterModuleType("java_plugin", PluginFactory)
+	registerJavaPluginBuildComponents(android.InitRegistrationContext)
+}
+
+func registerJavaPluginBuildComponents(ctx android.RegistrationContext) {
+	ctx.RegisterModuleType("java_plugin", PluginFactory)
 }
 
 // A java_plugin module describes a host java library that will be used by javac as an annotation processor.
diff --git a/java/testing.go b/java/testing.go
index b0290dc..82a2103 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -44,6 +44,7 @@
 	android.PrepareForTestWithAndroidBuildComponents,
 	// Make java build components available to the test.
 	android.FixtureRegisterWithContext(RegisterRequiredBuildComponentsForTest),
+	android.FixtureRegisterWithContext(registerJavaPluginBuildComponents),
 )
 
 // Test fixture preparer that will define default java modules, e.g. standard prebuilt modules.