8
8
import org .apache .maven .plugin .descriptor .InvalidPluginDescriptorException ;
9
9
import org .apache .maven .plugin .descriptor .PluginDescriptor ;
10
10
import org .apache .maven .plugin .plugin .DescriptorGeneratorMojo ;
11
- import org .apache .maven .project .MavenProject ;
12
11
import org .apache .maven .tools .plugin .DefaultPluginToolsRequest ;
13
12
import org .apache .maven .tools .plugin .extractor .ExtractionException ;
14
13
import org .apache .maven .tools .plugin .extractor .MojoDescriptorExtractor ;
22
21
import org .apache .maven .tools .plugin .scanner .MojoScanner ;
23
22
import org .codehaus .plexus .component .repository .ComponentDependency ;
24
23
import org .codehaus .plexus .util .xml .pull .XmlPullParserException ;
24
+ import org .gradle .api .artifacts .Configuration ;
25
+ import org .gradle .api .artifacts .component .ComponentIdentifier ;
26
+ import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
27
+ import org .gradle .api .artifacts .result .ResolvedArtifactResult ;
25
28
import org .gradle .api .file .ConfigurableFileCollection ;
26
29
import org .gradle .api .file .DirectoryProperty ;
27
30
import org .gradle .api .file .ProjectLayout ;
30
33
import org .gradle .api .plugins .JavaPluginExtension ;
31
34
import org .gradle .api .provider .Property ;
32
35
import org .gradle .api .tasks .*;
36
+ import org .gradle .api .tasks .Optional ;
33
37
34
38
import javax .annotation .Nonnull ;
35
39
import javax .inject .Inject ;
36
40
import java .io .IOException ;
37
41
import java .lang .reflect .Field ;
38
- import java .util .HashMap ;
39
- import java .util .List ;
40
- import java .util .Map ;
41
- import java .util .TreeMap ;
42
+ import java .util .*;
42
43
import java .util .stream .Collectors ;
43
44
44
45
/**
@@ -78,8 +79,18 @@ public abstract class DescriptorGeneratorTask extends AbstractGeneratorTask {
78
79
@ Input
79
80
public abstract Property <Boolean > getSkipErrorNoDescriptorsFound ();
80
81
82
+ @ InputFiles
83
+ public abstract ConfigurableFileCollection getMainSourceDirs ();
84
+
85
+ @ Internal
86
+ public abstract DirectoryProperty getMainOutputDirectory ();
87
+
81
88
public DescriptorGeneratorTask () {
82
89
getSkipErrorNoDescriptorsFound ().convention (false );
90
+
91
+ SourceSet main = getProject ().getExtensions ().getByType (JavaPluginExtension .class ).getSourceSets ().getByName (SourceSet .MAIN_SOURCE_SET_NAME );
92
+ getMainSourceDirs ().from (main .getAllJava ().getSourceDirectories ());
93
+ getMainOutputDirectory ().convention (main .getJava ().getClassesDirectory ());
83
94
}
84
95
85
96
/**
@@ -89,8 +100,9 @@ public DescriptorGeneratorTask() {
89
100
protected void generate () throws ExtractionException , InvalidPluginDescriptorException , XmlPullParserException , IOException , GeneratorException {
90
101
PluginDescriptor pluginDescriptor = new PluginDescriptor ();
91
102
92
- SourceSetContainer sourceSets = getProject ().getExtensions ().getByType (JavaPluginExtension .class ).getSourceSets ();
93
- MavenProject project = new MavenProjectWrapper (getProjectLayout (), sourceSets , getPomFile ().getAsFile ().get ());
103
+ MavenProjectWrapper project = new MavenProjectWrapper (getProjectLayout (), getPomFile ().getAsFile ().get ());
104
+ project .setMainSourceDirs (getMainSourceDirs ());
105
+ project .setMainOutputDirectory (getMainOutputDirectory ());
94
106
95
107
pluginDescriptor .setGroupId (project .getGroupId ());
96
108
pluginDescriptor .setArtifactId (project .getArtifactId ());
0 commit comments