我的项目 MAIN 包含 SubProject A 和 SubProject B ,当我在SubProject A和SubProject B中进行更改时
我必须为SubProject A和SubProject B做maven clean和maven安装 然后是MAIN项目更新。
有没有办法在单一配置中实现所有这些?
类似的东西:
配置MainProject: 清理,构建A,清理,构建B,清理,构建MainProject。
谢谢
答案 0 :(得分:2)
有没有办法在单一配置中实现所有这些?
当然可以。这是maven多模块项目的骨架:
父POM:
$ pod install
请注意<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group</groupId>
<artifactId>myProject</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>myProject</name>
<url>http://maven.apache.org</url>
<modules>
<module>moduleA</module>
<module>moduleB</module>
</modules>
<build>
....
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
....
</dependencies>
</dependencyManagement>
<dependencies>
....
</dependencies>
</project>
。
这是moduleA的POM:
<packaging>pom</packaging>
模块为moduleB,但依赖于moduleA。
<?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>
<artifactId>myProject</artifactId>
<groupId>my.group</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>moduleA<artifactId>
<name>moduleA</name>
<packaging>jar</packaging> <!-- this is default -->
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<!-- no version here, see dependencyManagemant in parent POM -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- no version here, see dependencyManagemant in parent POM --> <scope>test</scope>
</dependency>
</dependencies>
</project>
现在,只要您对模块进行更改,就可以在父上致电<?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>
<artifactId>nbaWorker</artifactId>
<groupId>de.lgn.aaabk</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>moduleB</artifactId>
<name>moduleB</name>
<packaging>jar</packaging> <!-- this is default -->
<dependencies>
<dependency>
<groupId>my.group</groupId>
<artifactId>moduleA</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<!-- no version here, see dependencyManagemant in parent POM -->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- no version here, see dependencyManagemant in parent POM --> <scope>test</scope>
</dependency>
</dependencies>
</project>
。
以下是更多信息: Tutorial How do I ...
From maven Homepage。在这个时候,没那么有用,而且链接断了。
答案 1 :(得分:1)
为此,我在我的顶级父POM中声明了一个配置文件,如此
...
SyntaxNode root = await document.GetSyntaxRootAsync().ConfigureAwait(false);
var interfaceDeclaration = root.DescendantNodes(node => node.IsKind(SyntaxKind.InterfaceDeclaration)).FirstOrDefault() as InterfaceDeclarationSyntax;
if (interfaceDeclaration == null) return;
var methodToInsert= GetMethodDeclarationSyntax(returnTypeName: "GetSomeDataResponse ",
methodName: "GetSomeData",
parameterTypes: new[] { "GetSomeDataRequest" },
paramterNames: new[] { "request" });
var newInterfaceDeclaration = interfaceDeclaration.AddMembers(methodToInsert);
var newRoot = root.ReplaceNode(interfaceDeclaration, newInterfaceDeclaration);
// this will format all nodes that have Formatter.Annotation
newRoot = Formatter.Format(newRoot, Formatter.Annotation, workspace);
workspace.TryApplyChanges(document.WithSyntaxRoot(newRoot).Project.Solution);
...
public MethodDeclarationSyntax GetMethodDeclarationSyntax(string returnTypeName, string methodName, string[] parameterTypes, string[] paramterNames)
{
var parameterList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(GetParametersList(parameterTypes, paramterNames)));
return SyntaxFactory.MethodDeclaration(attributeLists: SyntaxFactory.List<AttributeListSyntax>(),
modifiers: SyntaxFactory.TokenList(),
returnType: SyntaxFactory.ParseTypeName(returnTypeName),
explicitInterfaceSpecifier: null,
identifier: SyntaxFactory.Identifier(methodName),
typeParameterList: null,
parameterList: parameterList,
constraintClauses: SyntaxFactory.List<TypeParameterConstraintClauseSyntax>(),
body: null,
semicolonToken: SyntaxFactory.Token(SyntaxKind.SemicolonToken))
// Annotate that this node should be formatted
.WithAdditionalAnnotations(Formatter.Annotation);
}
private IEnumerable<ParameterSyntax> GetParametersList(string[] parameterTypes, string[] paramterNames)
{
for (int i = 0; i < parameterTypes.Length; i++)
{
yield return SyntaxFactory.Parameter(attributeLists: SyntaxFactory.List<AttributeListSyntax>(),
modifiers: SyntaxFactory.TokenList(),
type: SyntaxFactory.ParseTypeName(parameterTypes[i]),
identifier: SyntaxFactory.Identifier(paramterNames[i]),
@default: null);
}
}
在eclipse运行配置中,使用父POM路径作为基本目录,使用“build-all”作为配置文件。
请记住,您必须将父POM声明为另一个POMS的父级。